模板匹配适用于XSLT1.0,但不适用于XSLT2.0
我使用的是XSLT1.0,使用的是jre1.6中的内置处理器 当我使用Saxon将处理器更改为XSLT2.0时,大多数模板匹配突然失效模板匹配适用于XSLT1.0,但不适用于XSLT2.0,xslt,xslt-1.0,xslt-2.0,Xslt,Xslt 1.0,Xslt 2.0,我使用的是XSLT1.0,使用的是jre1.6中的内置处理器 当我使用Saxon将处理器更改为XSLT2.0时,大多数模板匹配突然失效 <xsl:template match="@*|node()" name="identity"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <x
<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>
除第一个模板标识外,以上所有模板均不起作用。
如何使它们同时在XSLT2.0和1.0中工作
输入xml为:
<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>
预期产出为:
<dynamicData source="MIG">
<customer name="Cyrus S" custType="P" country="US">
<invoice amount="250" invType="C" claimingSystem="EX001"/>
</customer>
</dynamicData>
这在XSLT1.0中是有效的。我不知道怎么做
<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>
及
如果您包含一个示例XML输入,我们可以自己进行测试。在$removeInvAttr中使用分隔字符串绝对不会在任何版本的XSLT中工作。也不能匹配任何内容,与XSLT版本无关。除了提供示例XML输入外,还应该清楚地描述不工作的含义。一个特定的错误消息将是理想的。怀疑类路径/打包问题。更正了我关于claimingSystem的输入/输出和模板的帖子。
<xsl:param name="removeInvAttr" select="'indexDefinition|services|paymentMethod'"/>
<xsl:variable name="removeAttrNames" select="tokenize($removeInvAttr)"/>
<xsl:template match="invoice/@*[name() = $removeAttrNames]"/>