I was using XSLT1.0 using inbuilt processors from jre1.6
When I changed my processor to XSLT2.0 using SAXONHE jars suddenly most of template matching are not working.
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@source[. = 'SG']">
<xsl:attribute name="source">MIG</xsl:attribute>
</xsl:template>
<xsl:template match="customer/@homeAddress"/>
<xsl:param name="removeInvAttr" select="'indexDefinition|services|paymentMethod'"/>
<xsl:template match="invoice/@*">
<xsl:for-each select="@*">
<xsl:if test="not(name() = $removeInvAttr)">
<xsl:call-template name="identity"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:variable name="vLowercaseChars_CONST" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="vUppercaseChars_CONST" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:template match="@country">
<xsl:attribute name="country"><xsl:value-of select="translate(. , $vLowercaseChars_CONST , $vUppercaseChars_CONST)"/></xsl:attribute>
</xsl:template>
<xsl:template match="@claimingSystem">
<xsl:if test="string-length(.) > 5">
<xsl:attribute name="claimingSystem"><xsl:value-of select="substring(.,1,5)"/></xsl:attribute>
</xsl:if>
</xsl:template>
All above templates not working except first template "identity".
How to make them work in both XSLT 2.0 and 1.0?
Input xml is:
<dynamicData source="SG">
<customer name="Cyrus S" homeAddress="NY" custType="P" country="us">
<invoice amount="250" invType="C" indexDefinition="SECR" services="TYRE_REP" paymentMethod="CC" claimingSystem="EX001-S1"/>
</customer>
</dynamicData>
Expected output is:
<dynamicData source="MIG">
<customer name="Cyrus S" custType="P" country="US">
<invoice amount="250" invType="C" claimingSystem="EX001"/>
</customer>
</dynamicData>
This works in XSLT 1.0.
<xsl:if test="not(name() = $removeInvAttr)">
with a delimited string in$removeInvAttr
would absolutely never have worked in any version of XSLT. Also<xsl:template match="/@claimingSystem">
cannot match anything, independent of the XSLT version. – Tomalak