我需要重寫一組<p>
和<lb>
節點。這是我最初的節點集:用xslt添加和重新排列節點來重寫XML生成的樹
<p>
text[1] and nodes[1] here
<pb/>
text[2] and nodes[2] here
<pb/>
text[3] and nodes[3] here
<pb/>
[...]
text[x] and any nodes[x] here
</p>
而這正是我需要的:
<p>text[1] and nodes[1] here</p>
<pb/>
<p>text[2] and nodes[2] here</p>
<pb/>
<p>text[3] and nodes[3] here</p>
<pb/>
<p>[...]</p>
<p>text[x] and nodes[x] here</p>
我設法爲進一步轉變變量撞他們重寫第一個和最後一個節點和文本:
<xsl:variable name="textAndNotes_1">
<p>
<xsl:copy-of select=" child::node()[not(preceding-sibling::*:pb)
and not(self::*:pb)]"/>
</p>
</xsl:variable>
[...]
<xsl:variable name="textAndNotes_x">
<p>
<xsl:copy-of select="child::node()[not(following-sibling::*:pb) and
not(self::*:pb)]"/>
</p>
</xsl:variable>
這也適用於第一個和最後一個<pb/>
。但我與內部<p>...</p>
和內部<pb/>
疊加,我不確定這是做到這一點的正確方法。我一直在尋找幾個小時而沒有找到答案。任何幫助?
所有最好的,特里斯坦
您可以使用XSLT 2.0嗎? –
是的,我可以使用XSLT 2.0。在此先感謝... T – Tristan
是不是''你想要包裝成'p'元素的真實內容?你能解釋哪些內容應該被包裝進一個'p'元素,哪一個不是? –