0

I have the following input xml:

    <?xml version='1.0' encoding='UTF-8'?>
    <fde-request xmlns="http://xml-schemas.xxx.com/bb/xxx.xsd"
        xmlns:cbe="http://xml-schemas.xxx.com/bb/xxx.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xml-schemas.xxx.com/bb/xxx.xsd xxx.xsd">

        <cbe:request-header
        user-id="mde"
        session-token="433"
        audit-id="9999"
        pearl-code="ca"
        interface-id="mf"
        system-name="sr"
        function-code="image"
        />

    <fde-parms
      function-code='b'
      sccf-serial='042463452400'
      type-process='H'>
    </fde-parms>
    </fde-request>

I need to get the following output xml by copying attribute to new element values:

    <?xml version='1.0' encoding='UTF-8'?>
    <fde-request xmlns="http://xml-schemas.xxx.com/bb/xxx.xsd"
        xmlns:cbe="http://xml-schemas.xxx.com/bb/xxx.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xml-schemas.xxx.com/bb/xxx.xsd xxx.xsd">

         <REQUEST-HEADER>
      <REQUEST-ID>mde</REQUEST-ID>
      <REQUEST-PEACODE>ca</REQUEST-PEACODE>
       </REQUEST-HEADER> 

    <fde-parms
      function-code='b'
      sccf-serial='042463452400'
      type-process='H'>
    </fde-parms>
    </fde-request>

BUT: I am getting this output xml with the following xslt:

    <xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates />
      </xsl:copy>
    </xsl:template>
        <xsl:template match="*[local-name(.)='request-header']">
        <xsl:variable name="sysname" select="@system-name"/>
        <xsl:variable name="peacode" select="@pearl-code"/>

    <REQUEST-HEADER>
    <REQUEST-ID><xsl:value-of select="$sysname"/></REQUEST-ID>
    <REQUEST-PEACODE><xsl:value-of select="$peacode"/></REQUEST-PEACODE>
    </REQUEST-HEADER>   
        </xsl:template> 
    </xsl:stylesheet>

That produces the wrong output: xmlns="" is populating, which is not what I want.

    <?xml version='1.0' encoding='UTF-8'?>
    <fde-request xmlns="http://xml-schemas.xxx.com/bb/xxx.xsd"
        xmlns:cbe="http://xml-schemas.xxx.com/bb/xxx.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xml-schemas.xxx.com/bb/xxx.xsd xxx.xsd">

         <REQUEST-HEADER **xmlns=""**>
      <REQUEST-ID>mde</REQUEST-ID>
      <REQUEST-PEACODE>ca</REQUEST-PEACODE>
       </REQUEST-HEADER> 

    <fde-parms
      function-code='b'
      sccf-serial='042463452400'
      type-process='H'>
    </fde-parms>
    </fde-request>

I need to remove this unnecessary empty namespace.
How would you modify the xslt to produce the right output?

1 Answer 1

1

In XSLT 1.0 (which I assume you're using; your example stylesheet is missing the start tag), xsl:copy always copies all namespace nodes too.

If you want to avoid copying a namespace, you need to recreate the element using xsl:element. Its namespace attribute is optional.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.