this questionの答えで間違いを見て、それを指摘したと思いました。私は間違っていると言われ、私の答えは後で削除されました。XSLで一致する子要素
私はまだ間違っていた方法を見ていません。したがって、私はここに投稿していると誰かが私の誤解を説明することを望む。
私が答えた答えは、apply-templatesの使用方法を説明したものです。これは、テンプレートがマッチするだろうか説明し、次のXMLとXSLを含んでいた:
<!-- sample XML snippet -->
<xml>
<foo /><bar /><baz />
</xml>
<!-- sample XSLT snippet -->
<xsl:template match="xml">
<xsl:apply-templates select="*" /> <!-- three nodes selected here -->
</xsl:template>
<xsl:template match="foo"> <!-- will be called once -->
<xsl:text>foo element encountered</xsl:text>
</xsl:template>
<xsl:template match="xml/*"> <!-- will be called twice -->
<xsl:text>other element countered</xsl:text>
</xsl:template>
私のコメントがあるべきで、最後のテンプレートました:現在のノードがすでに<xml>
<xsl:template match="*"> <!-- will be called twice -->
<xsl:text>other element countered</xsl:text>
</xsl:template>
私は言われました:
いいえ、xml/*は、次の子要素に一致するパターンです。要素名は xmlです。
このXMLで、
しかし、元の答えをテスト:
<xml>
<foo /><bar /><baz />
</xml>
そして、このXSLスタイルシート(上記のスニペットを記入):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="xml">
<xsl:apply-templates select="*" /> <!-- three nodes selected here -->
</xsl:template>
<xsl:template match="foo"> <!-- will be called once -->
<xsl:text>foo element encountered.
</xsl:text>
</xsl:template>
<xsl:template match="xml/*"> <!-- will be called twice -->
<xsl:text>other element countered.
</xsl:text>
</xsl:template>
</xsl:stylesheet>
私が手:
私が手に私の答えどおり<xsl:template match="*"> <!-- will be called twice -->
<xsl:text>other element countered.
</xsl:text>
</xsl:template>
:
に見えるfoo element encountered.
other element countered.
other element countered.
私はとの最後のテンプレートを置き換える場合は、私の '修正' バージョン
のテスト
other element countered.
other element countered.
other element countered.
正しい。
私の質問がガイドラインに違反しないことを願っていますが、間違っているとは思えません。
PS。私はまだコメントを投稿するのに十分なポイントがないので、他の質問に対する私の元の応答が答えとして投稿されたことになります。私は何が最善のことであるか分からなかった...
私の愚かな間違いを見つけてくれてありがとう、もう1つのスレッドで修正されました。これは何年もの間答えを見た他の誰もが気づかなかった。 – Tomalak