<body>
<h1>Main Title</h1>
<p class="sectiontitle>Title</p>
<p class="bodytext">some text</bodytext>
<ul>...</ul>
<p class="paragraphtitle>Subtitle</p>
<p class="bodytext">some text</bodytext>
</body>
或這一個地方的paragraphtitle和sectiontitle被顛倒:
<h1>Main Title</h1>
<p class="paragraphtitle>Title</p>
<p class="bodytext">some text</bodytext>
<ul>...</ul>
<p class="sectiontitle>Subtitle</p>
<p class="bodytext">some text</bodytext>
</body>
我改造這個XML結構到不同XML(DITA)的味道,爲此,我需要知道節點的第一位,因爲它告訴我如何處理文件的其餘部分。
除非我知道最先發生什麼,否則沒有其他辦法可以處理該文件。
我知道在任何這些標題之前都會有h1,h2,h3 ...元素。主標題和結束標籤之間可能有<p class=bodytext>
元素。這是非常隨機的。
我該如何判斷第一個內容:sectiontitle p或paragraphtitle p。
我曾與一些瘋狂的表情放在一個試圖選擇像:
body/p[@class='sectiontitle'][1]/preceding-sibling::p[@class!='paragraphtitle'][last()]/preceding-sibling::*[not(self::p[@class='sectiontitle' or @class='paragraphtitle']) and preceding-sibling::h1]
或
body/p[@class='paragraphtitle'][1]/preceding-sibling::p[@class!='sectiontitle'][last()]/preceding-sibling::*[not(self::p[@class='sectiontitle' or @class='paragraphtitle']) and preceding-sibling::h1]
,在大多數情況下(仍然需要調整的東西)的作品,但我覺得有必須更簡單地告訴哪個節點在可能性列表中首先出現。
有沒有辦法獲得絕對位置?像
if absposition(paragraphtitle[1]) < absposition(sectiontitle[1]) then
爲什麼你需要知道哪個是第一位的?你試圖在這裏解決的**真正**問題是什麼? –
我想識別文件以知道如何處理它,我知道2個形狀:首先是段落標題,首先是段落標題,基於此,我爲每一個採取不同的路徑。 – Flag