我需要遍历多节点结构,但该结构只能由前导节点标识,并且该前导节点之后的节点可能会有所不同。如何遍历XSL中的多节点结构
在这个例子中,我需要通过每个<title>-some_nodes
,<title>-some_other_nodes
块迭代
XML文件:
<books>
<title>book_one</title>
<price>price_for_book_one</price>
<notes>notes_for_book_one</notes>
<title>book_two</title>
<price>price_for_book_two</price>
</books>
所需的输出:
<div class="book">
<h1 id="title">book_one</h1>
<h2 id="values">
<p>price_for_book_one</p>
<p>notes_for_book_one</p>
</h2>
</div>
<div class="book">
<h1 id="title">book_two</h1>
<h2 id="values">
<p>price_for_book_two</p>
</h2>
</div>
我尝试:
<xsl:template match="/">
<xsl:for-each select="books/title">
<h1 id="title"><xsl:text>Title:</xsl:text>
<xsl:value-of select="." />
</h1>
<h2 id="values">
<!-- have other templates for matching all possible following-sibling nodes -->
<xsl:apply-templates select="following-sibling::*>
</h2>
</xsl:for-each>
</xsl:template>
但是这只会选择标题节点而不解析任何其他节点,因为“books/title”只选择标题节点。
注:<price>
和<notes>
是两个示例节点,有可能是在<title>
节点之间的任何东西,我有处理它们的其他模板,但如何选择它们是我的问题。
任何想法将不胜感激。
你忘了解释什么“不真的窝窝rk“...请编辑您的问题,并提供您需要的确切正确结果以及您实际得到的结果。另外,请描述实际结果究竟出了什么问题。 – 2011-03-16 02:15:19
感谢您的反馈,编辑过的问题。 – highlightall 2011-03-17 20:23:25