0
プレースホルダ付きHTMLテンプレートをXSLTを使用して最終HTMLに変換しようとしています。ネストされたHTMLスパン要素の変換
(簡体字)のHTMLテンプレートは以下のようになります。
<p>
<span class="condition" id="v6">Some text here
<span class="placeholder" id="v1" />
</span>
</p>
変換が
placeholder
クラスを持つすべてのspan
の要素を交換する必要があります。- 隠すか、我々が持っている(簡体字)XSLTがある
condition
クラス
を含む各span
要素を示しています。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:local="urn:local"
xmlns:s0="http://www.w3.org/1999/xhtml">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
<!-- Take the HTML template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--Replace every placeholder in the HTML template with the value from the XML data-->
<xsl:template match="span[@class='placeholder']">
<xsl:variable name="this" select="current()/@id"/>
<xsl:value-of select="'replaced'" />
</xsl:template>
<!-- Handle conditions based on custom logic -->
<xsl:template match="span[@class='condition']">
<xsl:variable name="this" select="current()/@id"/>
<xsl:if test="$this = 'v6'">
<xsl:value-of select="current()" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
プレースホルダスパンが条件スパンにネストされていない場合は、すべての作品良い。しかし、上記のHTMLの例では、それが動作しない、出力は次のようになります。
<p>Some text here</p>
我々はそれになりたいと思います:条件が実行されたかのように思え
<p>
Some text here
replaced
</p>
が、プレースホルダは実行されないか、何らかの形で上書きされます。基本的に、プレースホルダのspan要素は置き換えられません。
誰でも説明がありますが、間違っていますか?
ありがとうございます!代わりに現在のテキスト、Iちょうど再適用するノードを取るの
<!-- Handle conditions based on custom logic -->
<xsl:template match="span[@class='condition']">
<xsl:variable name="this" select="current()/@id"/>
<xsl:if test="$this = 'v6'">
<xsl:apply-templates select="node()"/> <<<<----------------
</xsl:if>
</xsl:template>
: