select 自闭元素之间的文本
select text between self closed elements
我想 select 文本在自闭 pet
元素之间。
输入:
<root>
<pet/>pet1<pet/><pet>cor1</pet><pet>vsr</pet><pet/>mnt<pet/>
</root>
预期输出:
<output>
<ou>pet1</ou>
<ou>mnt</ou>
</output>
逻辑:
这里pet1
和mnt
之间是自闭的<pet/>
。所以我想select这样的文字
已尝试 xpath:
text()[preceding-sibling::pet][following-sibling::pet]
以上 xpath 无效。我该如何解决这个问题?我正在使用 XSLT 2.0
谢谢。
您可以使用 text()[preceding-sibling::node()[1][self::pet[not(node())]][following-sibling::node()[1][self::pet[not(node())]]
在空 pet
元素之间查找文本节点;你无法区分XSLT/XPath中的<pet/>
和<pet></pet>
,这些是XSLT/XPath.
的树模型中没有体现的词法差异
我想 select 文本在自闭 pet
元素之间。
输入:
<root>
<pet/>pet1<pet/><pet>cor1</pet><pet>vsr</pet><pet/>mnt<pet/>
</root>
预期输出:
<output>
<ou>pet1</ou>
<ou>mnt</ou>
</output>
逻辑:
这里pet1
和mnt
之间是自闭的<pet/>
。所以我想select这样的文字
已尝试 xpath:
text()[preceding-sibling::pet][following-sibling::pet]
以上 xpath 无效。我该如何解决这个问题?我正在使用 XSLT 2.0
谢谢。
您可以使用 text()[preceding-sibling::node()[1][self::pet[not(node())]][following-sibling::node()[1][self::pet[not(node())]]
在空 pet
元素之间查找文本节点;你无法区分XSLT/XPath中的<pet/>
和<pet></pet>
,这些是XSLT/XPath.