I am working on call-template, where the source looks like this.
Source:
<Content>
<first>
<text>
Text
</text>
<link xmlns="Some namespace">
<AA>abcd</AA>
<BB>hi all</BB>
</link>
</first>
<second>
<link xmlns="Some other namespace">
<AA>abcd1</AA>
<BB>hi all21</BB>
</link>
</second>
<three>
<link xmlns="other namespace">
<AA>abcd2</AA>
<BB>hi all33</BB>
</link>
</three>
</Content>
XSLT written:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:n1="Some namespace" xmlns:n2="Some other namespace" xmlns:n3="other namespace">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="Content">
<xsl:call-template name="process">
<xsl:with-param name="item" select="first/n1:link" />
</xsl:call-template>
<xsl:call-template name="process">
<xsl:with-param name="item" select="second/n2:link" />
</xsl:call-template>
<xsl:call-template name="process">
<xsl:with-param name="item" select="three/n3:link" />
</xsl:call-template>
</xsl:template>
<xsl:template name="process">
<xsl:param name="item" />
<xsl:value-of select="$item/AA" />
</xsl:template>
</xsl:stylesheet>
I am getting blank output.I know the reason because i didn’t append the namespace prefix for it. like “n1:A” like that.
As the is coming multiple times. I wrote a template and called where ever needed. But the name space of each link is diffrent. How to do I modify my code so that I can reuse the template “process”.
Can any one help, how Do I modify the “process” template accordingly to handle with diffrent namespace but same structure.
Thank you.
Instead of doing this
You could change the expression to this
i.e. Check the name without namespace is ‘AA’, and that it has the same namespace as the parent element. This would mean if you had another ‘AA’ element within the ‘link’ element with a different namespace, it would not be picked up.