一部のセクションを処理して再利用するためのテンプレートを作成したいと思います。
以下のXMLでは、メッセージが、、、ごとに繰り返されていることがわかります。必要に応じて処理して呼び出すテンプレートを作成したいと思います。
<Data>
<A>
<text>this is text</text>
<Message>
<local>Local link</local>
<STD>External link</STD>
</Message>
</A>
<B>
<info>Information</info>
<Message>
<local>Local uri link</local>
<STD>External link uri</STD>
</Message>
</B>
<C>
<longtext>Long Text</longtext>
<Message>
<local>Local uri link</local>
<STD>External link uri</STD>
</Message>
</C>
<Data>
必要な出力:
<Information>
<AA>
this is text
<MSG local value="Local uri link" STD value="External link"/>
</AA>
<BB>
Information
<MSG local value ="Local uri link" STD value="External link"/>
</BB>
<CC>
Long Text
<MSG local value="Local uri link" STD value="External link"/>
</CC>
<Information>
すべてのノードでタグを処理している間、私はA、B、Cのすべてのタグのコードを書いています。
書かれたサンプルコード
<Information>
<xsl:template match="A">
<AA>
<xsl:value-of select="text"/>
<xsl:element name="MSG">
<xsl:attribute name="local value">
<xsl:value-of select="Message/local"/>
</xsl:attribute>
<xsl:attribute name="STD value">
<xsl:value-of select="Message/STD"/>
</xsl:attribute>
</AA>
</Information>
同様に、すべてのテンプレートについて、ブロックMSGのコードを明示的に記述しています。
次に、を処理するための別のテンプレートを作成します。そして、私はすべてのテンプレートからこのテンプレートを呼び出したいと思います。
基本的に私は処理するために書かれたコードを再利用したい
誰かが私にそれをする方法を手伝ってくれますか?
ありがとうございました。