-1

「meta」および「answer」以外のすべての要素を受け取り、それらを「my_question」テンプレートに入れる XSLT テンプレートを作成するにはどうすればよいですか? たとえば、以下の XML を指定すると...

<question>
    <meta>
        ...
    </meta>
    <para />
    <para>Why?</para>
    <answer weight="1" correctness="0">
        ...
    </answer>
    <answer weight="1" correctness="0">
        ...
    </answer>
    <answer weight="1" correctness="100">
        ...
    </answer>
    <answer weight="1" correctness="0">
        ...
    </answer>
</question>

私は結果が

<my_question>
    <para />
    <para>Why?</para>        
</my_question>
4

2 に答える 2

1

ID テンプレートから始めます。

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

実行すると、すべてが変換されることがわかります。

次に、たとえば次のように、ノードを選択的に削除します。

<xsl:template match="answer" />

詳細については、次のリンクを参照してください: http://www.xmlplease.com/xsltidentity 非常に詳細です。幸運を!

于 2012-06-08T20:46:29.673 に答える
1

ID テンプレートはあなたの友達です

<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 version="2.0">

 <xsl:output method="xml" encoding="utf-8" indent="yes"/>

 <xsl:template match="/">
     <my_question>
        <xsl:apply-templates select="question"/>
     </my_question>
 </xsl:template>

 <!-- ignores the specified elements. Adjust for nesting if necessary. -->
 <xsl:template match="meta | answer"/>

 <!-- Pass everything else -->
 <xsl:template match="@*|node()">
 <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
 </xsl:template>
</xsl:stylesheet>
于 2012-06-08T20:46:39.573 に答える