【问题标题】:xpath for the below code?以下代码的xpath?
【发布时间】:2015-02-06 00:48:25
【问题描述】:

我正在尝试为所有级别等于 <instrText xml:space="preserve"> 级别的 <fldChar fldCharType="end"/> 标记查找 xpath。 我试过/word/r/instrText/preceding::fldChar 但它给出了前面的所有<fldChar fldCharType="end"/> 标签。我只需要相同级别的<fldChar。请建议我整理一下。

 <?xml version="1.0" encoding="UTF-8"?>
    <word>
        <r rsidRPr="00A35D44">
                                <rPr>
                                      <rFonts ascii="Times New Roman" eastAsia="Times New Roman"/>
                                    </rPr>
                                <fldChar fldCharType="begin"/>
                              </r>
                          <r rsidRPr="00A35D44">
                                <rPr>
                                      <rFonts ascii="Times New Roman" eastAsia="Times New Roman"/>
                                    </rPr>
                                <instrText xml:space="preserve"> XE “efficiency” </instrText>
                              </r>
                          <r rsidRPr="00A35D44">
                                <rPr>
                                      <rFonts ascii="Times New Roman" eastAsia="Times New Roman"/>
                                    </rPr>
                                <fldChar fldCharType="end"/>
                          </r>
      <fldChar fldCharType="end"/>
                          <r rsidRPr="00A35D44">
                                <rPr>
                                      <rFonts ascii="Times New Roman" eastAsia="Times New Roman"/>
                                      <b val="0"/>
                                    </rPr>
                                <t>,</t>
                              </r>
                          <r rsidRPr="00A35D44">
                                <rPr>
                                      <rFonts eastAsia="Times New Roman" hAnsi="Arial Unicode MS"/>
                                    </rPr>
                                <instrText xml:space="preserve"> and equity</instrText>
                              </r>
                          </word>

【问题讨论】:

  • 还有一个preceding-sibling轴,但我不确定这是否符合你对同级别的定义。
  • 我也尝试了前兄弟选项,但我没有得到结果 Mr.Martin Honnen
  • 您能告诉我们您要选择样本中的哪些元素吗?
  • //fldChar[@fldCharType="end"][some $it in //instrText[@xml:space = "preserve"] satisfies count(./ancestor::node()) eq count($it/ancestor::node())] 是否提供您想要的元素?我试图通过提出 XPath 建议来理解您对“同一级别”的定义,您可能需要详细说明这种情况。

标签: xml xpath xpath-2.0


【解决方案1】:

根据我们在 cmets 中的交换,您正在寻找表达式 //fldChar[@fldCharType="end"][some $it in //instrText[@xml:space = "preserve"] satisfies count(./ancestor::node()) eq count($it/ancestor::node())]。或者更短一点的//fldChar[@fldCharType="end"][some $it in //instrText[@xml:space = "preserve"] satisfies count(ancestor::node()) eq count($it/ancestor::node())]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 2017-01-31
    • 2021-12-16
    • 2014-10-05
    • 1970-01-01
    相关资源
    最近更新 更多