2016-03-22 5 views
3

私は奇妙な行動を見ました。次 は詳細です:別のテンプレートで使用すると、アイデンティティ変換の変な動作

XSLTコード

<?xml version="1.0" encoding="UTF-8" ?> 

<xsl:template match="child[@include='1']"/> 

<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 

ソースXML

<?xml version="1.0" encoding="UTF-8"?> 
<Parent> 
    <child include='1'> 
     <Attribute>Attribute1</Attribute> 
    </child> 
    <child include='1'> 
     <Attribute>Attribute2</Attribute> 
    </child> 
    <child include='0'> 
     <Attribute>Attribute3</Attribute> 
    </child> 
    <child include='0'> 
     <Attribute>Attribute4</Attribute> 
    </child> 
</Parent> 

そして、私の結果は次のとおりです。

我々は結果が条件

<xsl:template match="child[@include='1']"/> 
にacccording以下のようにする必要があります適用され、通常の状態にAcoording
<Parent> 
    <child include="0"> 
     <Attribute>Attribute3</Attribute> 
    </child> 
    <child include="0"> 
     <Attribute>Attribute4</Attribute> 
    </child> 
</Parent> 

うまくいけば、私は詳細に説明している

:私はあなたが上のあなたの期待をベースに何かわからないSample Code

答えて

1

: これは、コードとXSLTプロセッサへのリンクです。

最初のテンプレートの優先度は0.5ですが、2番目のテンプレート(恒等変換)のテンプレートの優先度は-0.5です。

したがって、include属性が1のすべてのchild要素に適用されるテンプレートが最初のテンプレートです。 このテンプレートは空ですので、何も出力しません。結果として、include属性が1child要素は出力されません。

他のすべてのノードは、それらを(再帰によって子孫によって)出力にコピーする2番目のテンプレートと照合されます。

+0

ありがとう@マイケル、これは私が探していたものです:) – Hikmat

関連する問題