1
我試圖提取一個有趣的節點(這裏big-structured-text
)的文本,但這個節點中有一些孩子,我想跳過(這裏title
,subtitle
和code
)。那些「刪除」節點可以有孩子。提取文本跳過內容
的樣本數據:
<root>
<big-structured-text>
<section>
<title>Introduction</title>
In this part we describe Australian foreign policy....
<subsection>
<subtitle>Historical context</subtitle>
After its independence...
<meta>
<keyword>foreign policy</keyword>
<keyword>australia</keyword>
<code>
<value>XXHY-123</value>
<label>IRRN</label>
</code>
</meta>
</subsection>
</section>
</big-structured-text>
<!-- ... -->
<big-structured-text>
<!-- ... -->
</big-structured-text>
</root>
到目前爲止,我已經試過:
<xsl:for-each
select="//big-structured-text">
<text>
<xsl:value-of select=".//*[not(*)
and not(ancestor-or-self::code)
and not(ancestor-or-self::subtitle)
and not(ancestor-or-self::title)
]" />
</text>
</xsl:for-each>
但這只是把那些沒有任何孩子的節點,它會採取keyword
,但不以下介紹標題文字
我也試過了:
<xsl:for-each
select="//big-structured-text">
<text>
<xsl:value-of select=".//*[
not(ancestor-or-self::code)
and not(ancestor-or-self::subtitle)
and not(ancestor-or-self::title)
]" />
</text>
</xsl:for-each>
但是,這是多次迴應有趣的文本,有時不感興趣(每個節點爲自己迭代一次,然後每個祖先一次)。
你可以在你的代碼中詳細說明哪些部分告訴複製不在給定標籤內的東西嗎? – AsTeR
@AsTeR在我的代碼中沒有任何明確的表達 - 這是我在第一行中鏈接到的默認規則的結果。這些默認規則基本上與' xsl:template>'和' xsl:template>的值。使其工作的事情是,明確的「match =」標題|代碼「'模板覆蓋默認的」*「''。 –
好的感謝您的解釋,我會嘗試一個良好的睡眠後;) – AsTeR