2013-12-17 35 views
0

我使用XSLT1.0使用內置處理器從jre1.6
當我使用SAXONHE將處理器更改爲XSLT2.0時突然大部分模板匹配不是加工。模板匹配工作在XSLT1.0但不是在XSLT2.0

<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> 

除了第一個模板「identity」,以上所有模板都不起作用。
如何使它們同時適用於XSLT 2.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> 

這適用於XSLT 1.0。

+2

如果包括樣本XML輸入,我們可以測試這個自己。 –

+0

如果test =「not(name()= $ removeInvAttr)」>''在'$ removeInvAttr'中帶有分隔符的字符串'絕對不會在任何*版本的XSLT中工作。另外''xsl:template match =「/ @ claimingSystem」>'無法匹配任何內容,與XSLT版本無關。 – Tomalak

+0

除了提供示例XML輸入之外,您還應該清楚地描述「不工作」的含義。一個特定的錯誤信息將是理想的。 – kjhughes

回答

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> 

可以做任何事情的參數是與一間酒吧|,並作爲重要的分隔的多個名稱的字符串,match="invoice/@*"xsl:for-each select="@*"不會選擇任何內容(作爲屬性節點作爲上下文節點本身沒有任何屬性節點)。

所以我懷疑你想

<xsl:param name="removeInvAttr" select="'indexDefinition|services|paymentMethod'"/> 
<xsl:variable name="removeAttrNames" select="tokenize($removeInvAttr)"/> 

<xsl:template match="invoice/@*[name() = $removeAttrNames]"/>