2011-01-12 4 views
0

<indicator itype="ST" ind="U"/>のようなxmlタグを<indicator itype="ST" ind="HELLO"/>に置き換えます。私が使用しているxsltスタイルシートは、次のようになります。複雑な一致式を使用して属性値を置き換えます

<?xml version="1.0" encoding="utf-8" ?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        version="1.0"> 
    <xsl:template match = "@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select = "@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 
    <xsl:template match = "indicator[@itype='ST' and @ind='U']"> 
    <xsl:attribute name = "ind"> 
     <xsl:text>HELLO</xsl:text> 
    </xsl:attribute> 
    </xsl:template> 
</xsl:stylesheet> 

スタイルシートが機能せず、プロセッサが例外をスローします。どうすれば修正できますか?

答えて

1

属性値を置き換える場合は、属性ノードを一致させる必要があります。このスタイルシート:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="indicator[@itype='ST']/@ind[.='U']"> 
     <xsl:attribute name="ind"> 
      <xsl:text>HELLO</xsl:text> 
     </xsl:attribute> 
    </xsl:template> 
</xsl:stylesheet> 

出力:魔法のように

<indicator itype="ST" ind="HELLO"></indicator> 
+0

Wors! –

+0

@BjörnLindqvist:そ​​れは助けになってうれしいです。 –

関連する問題