0

I am converting an XML to another using xslt, I have the namespace prefix for all tags, for example "ns9". In some places I am calling a template to generate the element within, where I am missing the namespace prefix. I tried to add namespace in the template, but it does not reflect.

 <xsl:call-template name="split">
     <xsl:with-param name="list" select="FlightReferences"/>
     <xsl:with-param name="delimiter" select="' '"/>
   <xsl:with-param name="tag" select="'PaxJourneyRefID'"/>
</xsl:call-template>

The response is as below, for the tag PaxJourneyRefID namespace prefix is missing.

 <ns9:OriginDest>
   <ns9:DestCode>DXB</ns9:DestCode>
   <ns9:OriginCode>LHR</ns9:OriginCode>
   <ns9:OriginDestID>LHRDXB</ns9:OriginDestID>
  <PaxJourneyRefID>Flight1</PaxJourneyRefID>
</ns9:OriginDest>

Tried adding name space in the template declaration,

<xsl:template name="split">
<xsl:param name="list"/>
<xsl:param name="delimiter"/>
<xsl:param name="tag"/>
<xsl:choose>
    <xsl:when test="contains($list, $delimiter)">
        <xsl:element name="{$tag}" xmlns:ns9="http://www.example.com/IATA/2015/00/2018.2/Sample" >
            <xsl:value-of select="substring-before($list,$delimiter)"/>
        </xsl:element>
        <xsl:call-template name="split">
            <xsl:with-param name="list" select="substring-after($list,$delimiter)"/>
            <xsl:with-param name="delimiter" select="$delimiter"/>
            <xsl:with-param name="tag" select="$tag"/>
        </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
        <xsl:choose>
            <xsl:when test="$list = ''">
                <xsl:text/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:element name="{$tag}">
                    <xsl:value-of select="$list"/>
                </xsl:element>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:otherwise>
</xsl:choose>

1 Answer 1

1

You can use a prefix in xsl:element name e.g. <xsl:element name="ns9:{$tag}">.

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

1 Comment

Thank you so much for the answer, it got worked along with namespace! '<xsl:element name="ns9:{$tag}" namespace="example.com/IATA/2015/00/2018.2/Sample">'

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.