Xpath获得具有分类文本的第一个祖先

时间:2013-11-11 10:12:05

标签: xpath umbraco ancestor

我试图找到一个带有特定@id的元素的第一个祖先,其中祖先的元素“metaCategory”包含文本......

所以伪:带有@id = XXXX的元素 - >获取第一个祖先,其中metaCategory text()不为空

希望这是有道理的。

结构示例:

<SubFrontpage id="2049" parentID="1112" level="3" writerID="9" creatorID="1" nodeType="1107" template="1297" sortOrder="1" createDate="2010-11-02T14:41:51" updateDate="2013-10-28T10:38:41" nodeName="Demenssygdomme" urlName="demenssygdomme" writerName="Eksponent" creatorName="Webmaster" path="-1,1086,1112,2049" isDoc="">
    <shortIntro><![CDATA[bla bla bla]]></shortIntro>
    <body><![CDATA[yada yada]]></body>
    <browserTitle>
    </browserTitle>
    <date>2010-11-02T14:41:00</date>
    <showEditDate>0</showEditDate>
    <showToTop>0</showToTop>
    <showPublishedDate>0</showPublishedDate>
    <image>
    </image>
    <navigationTitle>
    </navigationTitle>
    <hideFromNavigation>0</hideFromNavigation>
    <hideFromSitemap>0</hideFromSitemap>
    <metaDescription>
    </metaDescription>
    <metaKeywords>
    </metaKeywords>
    <metaNoIndex>0</metaNoIndex>
    <metaNoIndexOnDescendents>0</metaNoIndexOnDescendents>
    <umbracoUrlAlias>
    </umbracoUrlAlias>
    <keywords><![CDATA[]]></keywords>
    <writtenBy>
    </writtenBy>
    <metaCategory><![CDATA[5991]]></metaCategory>
    <boxes><![CDATA[4105,2210,2208]]></boxes>
    <macroContainer><![CDATA[]]></macroContainer>
    <mainMacroNarrow><![CDATA[]]></mainMacroNarrow>
    <Document id="3477" parentID="2080" level="4" writerID="3" creatorID="3" nodeType="1070" template="1045" sortOrder="0" createDate="2011-01-19T09:37:18" updateDate="2011-03-03T11:01:09" nodeName="Aktører i udredningsforløbet" urlName="aktoerer-i-udredningsforloebet" writerName="Jesper Bøgel Jensen" creatorName="Jesper Bøgel Jensen" path="-1,1086,1112,2080,3477" isDoc="">
      <shortIntro><![CDATA[BLABLA]]></shortIntro>
      <body><![CDATA[YADA]]></body>
      <browserTitle>
      </browserTitle>
      <date>2011-01-19T09:37:00</date>
      <showEditDate>0</showEditDate>
      <showToTop>1</showToTop>
      <showPublishedDate>0</showPublishedDate>
      <image>
      </image>
      <navigationTitle>
      </navigationTitle>
      <hideFromNavigation>0</hideFromNavigation>
      <hideFromSitemap>0</hideFromSitemap>
      <metaDescription>
      </metaDescription>
      <metaKeywords>
      </metaKeywords>
      <metaNoIndex>0</metaNoIndex>
      <metaNoIndexOnDescendents>0</metaNoIndexOnDescendents>
      <umbracoUrlAlias>
      </umbracoUrlAlias>
      <macroContainer><![CDATA[]]></macroContainer>
      <keywords><![CDATA[3300]]></keywords>
      <boxes><![CDATA[1350]]></boxes>
      <writtenBy>
      </writtenBy>
      <linksHeading>
      </linksHeading>
      <links>
        <links />
      </links>
      <test>
      </test>
    </Document>
</SubFrontpage>

1 个答案:

答案 0 :(得分:3)

未进行测试,因为未提供测试数据。

//@id[.="XXX"]/ancestor::*[metaCategory/text()][1]