2017-02-24 8 views
0

xsltで条件付きコピーを実行するにはどうすればよいですか?インスタンスだから、サブエレメント値に基づくサブノードの重複

<Person> 
    <Name>John</Name> 
    <Sex>M</Sex> 
</Person> 
<Person> 
    <Name>Jane</Name> 
    <Sex>F</Sex> 
</Person> 

の名前= "ジョン" は、その後場合:

<Person> 
    <Name>John</Name> 
    <Sex>M</Sex> 
</Person> 
<Copied> 
    <Name>John</Name> 
    <Sex>M</Sex> 
</Copied> 
<Person> 
    <Name>Jane</Name> 
    <Sex>F</Sex> 
</Person> 

は、これまでのところ私は、XSLTのこのビットを持っている:

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

これはジェーン」のコピーを作成しますもあります"条件付きでこれをどのように複製できますか?

あなたが行うことができ

答えて

3

<xsl:template match="Person"> 
    <xsl:copy> 
      <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
    <xsl:if test="Name='John'"> 
     <Copied> 
       <xsl:apply-templates select="node()|@*"/> 
     </Copied> 
    </xsl:if> 
</xsl:template> 

それとも:

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

<xsl:template match="Person[Name='John']"> 
    <xsl:copy-of select="."/> 
    <Copied> 
      <xsl:copy-of select="*"/> 
    </Copied> 
</xsl:template> 
関連する問題