2017-01-26 8 views
0

XSLTを使用してXML文書を変換しようとしています。元のXML文書の一部の要素は、私のXSL文書では使用されていませんが、これらの要素の値が結果に追加されます。どのように私はそのような要素を省略することができますか?例:XSLT変換中に未使用のXML要素を省略します。

XML

<?xml version="1.0"?> 
<data> 
    <id>1</id> 
    <name>Test</name> 
    <description>Test description</description> 
</data> 

XSL

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> 
    <xsl:template match="id"> 
     <id> 
      <xsl:apply-templates/> 
     </id> 
    </xsl:template> 
</xsl:stylesheet> 

結果

<id>1</id>TestTest description 

期待される結果

<id>1</id> 

答えて

1

あなたが見るのは、テキストノードをデフォルトとしてコピーするbuilt-in template rulesの結果です。これを防ぐために

最も簡単な方法は、より具体的にある - 例えば、実行します。

<xsl:template match="/data"> 
    <xsl:copy-of select="id"/> 
</xsl:template> 
関連する問題