我有一个相当愚蠢的问题。如何确保我的XML混合内容节点不会混淆?比方说,我有一个类似于这样的XML结构。
<root>
<book>
<title>Stuff</title>
<description> This book is <i>great</i> if you need to know about stuff.
I suggest <link ref="Things">this one</link> if you need to know
about things. </description>
</book>
[other books]
</root>
我需要最终的内容看起来像这样
<h1>List of books</h1>
<h2><a name="Stuff"/>Stuff</h2>
<p> This book is <i>great</i> if you need to know about stuff.
I suggest <a href="#Things">this one</a> if you need to know
about things. </p>
但是我无法提取文本节点的部分内容,我总是获取整个节点。我正在使用后代轴。有什么线索可以告诉我我做错了什么吗?
这是我的XSLT:
<xsl:template match="description/*">
<xsl:for-each select="following-sibling::*">
<xsl:choose>
<xsl:when test="name(.)='link'">
<a href="{@ref}"><xsl:value-of select="."/></a>
</xsl:when>
<xsl:when test="name(.)='em'">
<em><xsl:value-of select="."/></em>
</xsl:when>
<xsl:otherwise><p><xsl:value-of select="."/></p></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
请注意,所附的XML和生成的html仅为示例,我需要处理一些更大的结构,但出于清晰起见,我没有将其包含在内。