2016-04-25 7 views
0

まず、xmlのサンプルを提供してみましょう。XSLT 1.0を使用してXML内の特定の要素をコピーする方法

<a>1</a> 
<b>1</b> 
<c>1</c> 
<d>1</d> 
<e>1</e> 
<f>1</f> 

ノードをaからb、eからfにコピーすることは可能です。私はノードcとdを無視する必要があります。

要素をコピーできる<xsl:copy>がありますが、元のXMLから特定の要素を取得する必要があります。

ありがとうございます。

+0

。変換の予想される出力を表示し、各ノードで同じ値の例を使用しないでください。 –

答えて

0

もちろん、必要な要素を削除できます。アイデンティティ変換の後、指定された要素に空のテンプレートを書き込むだけです。

ソースXML

<root> 
    <a>1</a> 
    <b>1</b> 
    <c>1</c> 
    <d>1</d> 
    <e>1</e> 
    <f>1</f> 
</root> 

XSLT 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:strip-space elements="*"/> 

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

    <!-- Empty Template to Remove Elements --> 
    <xsl:template match="c|d"/> 

</xsl:stylesheet> 

出力XML

また
<root> 
    <a>1</a> 
    <b>1</b> 
    <e>1</e> 
    <f>1</f> 
</root> 

、パートを選択保つためにicularノード:あなたの質問は明確ではない

XSLT 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:strip-space elements="*"/> 

    <!-- Root Template Match -->  
    <xsl:template match="root"> 
    <xsl:copy> 
     <xsl:apply-templates select="a|b|e|f"/> 
    </xsl:copy> 
    </xsl:template> 

    <!-- Select Particular Elements --> 
    <xsl:template match="a|b|e|f"> 
     <xsl:copy-of select="."/> 
    </xsl:template> 

</xsl:stylesheet> 
関連する問題