我有以下HTML結構:選擇每個節點和兄弟姐妹(直到該節點的下一個出現)使用XPath
<document>
<ol>a question</ol>
<div>answer</div>
<div>answer</div>
<ol>another question</ol>
<div>answer</div>
<ol>question #3</ol>
...
</document>
我想採取<ol>
節點和下面<div>
節點,直到下一個<ol>
節點,所以我可以將它們像
<vce>
<topic>
<question> ... </question>
<answer> ... </answer>
</topic>
...
</vce>
一個XML到目前爲止,我有以下
<xsl:for-each select="//body/ol">
<document>
<content name="question">
<xsl:value-of select="." />
</content>
<content name="answer">
<xsl:for-each
select="./following-sibling::div !!! need code here !!!>
<xsl:value-of select="." />
</xsl:for-each>
</content>
</document>
</xsl:for-each>
我得到的問題很好,但我有麻煩的答案。我曾試着跟隨,前面,而不是,爲每個組,...。有很多類似的問題,但不是以這種格式退出,因爲我的html文件中沒有真正的子結構。
您的處理器是否支持XSLT 2.0? –
不,我使用的Watson Explorer只支持1.0,我想。 – RudyVerboven
你檢查了這個話題http://stackoverflow.com/questions/10859703/xpath-select-all-elements-between-two-specific-elements? – Ievgen