我的XML有以下情況。如何使用XSLT分析嵌套標記?
<content>
<para>text-1 <emphasis type="bold">text-2</emphasis> text-3</para>
</content>
欲解析它象下面
<content>
<p>text-1 <b>text-2</b> text-3</p>
</content>
我已經創建我的XSLT如下上面提供
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" encoding="ISO-8859-1" indent="no"/>
<xsl:template name="para">
<p>
<xsl:value-of select="text()" disable-output-escaping="yes"/>
<xsl:for-each select="child::*">
<xsl:if test="name()='emphasis'">
<xsl:call-template name="emphasis"/>
</xsl:if>
</xsl:for-each>
</p>
</xsl:template>
<xsl:template name="emphasis">
<xsl:if test="attribute::type = 'bold'">
<b>
<xsl:value-of select="text()" disable-output-escaping="yes"/>
</b>
</xsl:if>
</xsl:template>
<xsl:template match="/">
<content>
<xsl:for-each select="content/child::*">
<xsl:if test="name()='para'">
<xsl:call-template name="para"/>
</xsl:if>
</xsl:for-each>
</content>
</xsl:template>
</xsl:stylesheet>
XSLT正在產生象下面
<content>
<p>text-1 text-3<b>text-2 </b></p>
</content>
輸出請用你的建議引導我estions,我怎麼能得到我的慾望輸出?
在此先感謝!
任何建議/輸入/幫助非常感謝!
+1一個很好的答案 –