XSLT 替换节点中的 html



我不知道如何在 html 输出中将guiLabel转换为我正在尝试获取以下html

输出:

<p>lorem 1</p>
<p>lorem ipsum <strong>dolore</strong> amet</p>
<p>lorem 3</p>

从以下 XML:

<para>1</para>
<para>lorem ipsum <guiLabel>dolore</guiLabel> amet</para>
<para>3</para>

我的 XSL 文件:

<xsl:for-each select="./*">
<xsl:choose>
<xsl:when test=". instance of element(para)">
<p><xsl:value-of select="."/></p>
</xsl:when>
</xsl:choose>
</xsl:for-each>

与其进行xsl:for-each,不如使用模板化方法,对要更改的元素进行xsl:apply-templates,然后使用单独的模板匹配。

试试这个 XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="para">
<p>
<xsl:apply-templates />
</p>
</xsl:template>
<xsl:template match="guiLabel">
<strong>
<xsl:apply-templates />
</strong>
</xsl:template>  
</xsl:stylesheet>

最新更新