【发布时间】:2013-05-03 10:31:40
【问题描述】:
我正在尝试为 XML 文件构建一个 XSLT 文件,如下所示,它使用了无效的标签嵌套:
<Page>
<Content>
<par>This content <i>contains</i> some HTML <b><i>tags</i></b>.</par>
<par>This content <b>also</b> contains some HTML <i><b>tags</b></i>.</par>
</Content>
</Page>
现在如果我想将内容输出到一个新文档,我有这样的东西:
<xsl:template match="Page/Content">
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:for-each select="par">
<xsl:apply-templates select="."/>
</xsl:for-each>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
</xsl:template>
<xsl:template match="par">
<p><xsl:value-of select="." /></p>
</xsl:template>
<xsl:template match="b">
<strong><xsl:value-of select="." /></strong>
</xsl:template>
<xsl:template match="i">
<em><xsl:value-of select="." /></em>
</xsl:template>
我的问题是我需要如何编辑template match="par" 以便正确显示<b> 和<i> 标签?
我尝试过类似的东西
<xsl:template match="par">
<p>
<xsl:apply-templates select="i"/>
<xsl:apply-templates select="b"/>
<xsl:value-of select="." /></p>
</xsl:template>
但这总是会导致输出顺序不正确,因为<i> 和<b> 标记显示在完整段落之前。
有没有可能在不改变原始 XML 格式的情况下做到这一点?
【问题讨论】: