XPath normalize-space()不能用作step函数吗?
我刚刚设计了一个XPath表达式来查找所有空元素并在结束后直接返回文本。XPath normalize-space()不能用作step函数吗?
我已经在OXYGEN中测试了这个XPath,并返回了我正在寻找的内容。由于我还不知道的原因,我无法在Visual Studio(C#)中这样做。
XPath表达式:
//xref[not(@href)]/normalize-space(substring(following-sibling::text()[1], 1, 20))
这里是DITA(XML)文件,该文件中的XPath的搜索的一个示例:
<?xml version="1.0" encoding="UTF-8"?>
<topic id="topic_50038EEEBC214A0EBF0660DCFFCF69C6">
<title> Postulated Piping Failures in Fluid Systems Outside of
Containment</title>
<prolog>
<author/>
</prolog>
<body>
<p>
<b>Definitions</b>
</p>
<p>
<u>Leakage</u>
</p>
<p>
<xref
href="t1.3.2.2_System Quality Group Classifications.dita#topic_AE87340A0F424D07B0E301E243CCB7B2"
format="dita" scope="local"><?xm-replace_text System Quality Group Classifications?></xref>
TEXT
</p>
<p>
<u>
</u>TEXT
<xref></xref>5.2
</p>
</body>
</topic>
在氧气,使用XPath棒,结果是“5.2”,这正是我想要检索的。
这里是C#来检索节点:
String xPathFindXREF = "//xref[not(@href)]/normalize-space(substring(following-sibling::text()[1], 1, 20))";
XmlNodeList xmlNodeList = currFile.SelectNodes(xPathFindXREF);
是否有可能使用XPath功能,如在C#normalize-space()
?
您的XPath表达式需要XPath 2.0,它支持Oxygen,但本机C#库不支持。
顺便说一下,它不是normalize-space()
支持这里有问题,因为这两个版本的XPath支持;它使用normalize-space()
作为步骤函数,而不是需要XPath 2.0的谓词。
您的选择是为支持XPath 2.0的C#使用XPath库,或者通过C#迭代XPath选定节点,并分别标准化每个节点的字符串值。
谢谢。那是我寻找的那种答案:)。 – EnglischerZauberer
可能重复[如何获得normalize-space()xpath函数的工作?](https://*.com/questions/1829176/how-to-get-the-normalize-space-xpath-function对工作) –