简体   繁体   English

如何在Xpath中使用多个条件?

[英]How to Use multiple conditions in Xpath?

New to Xpath. Xpath新手。 Was trying in to use XML task in SSIS to load some values. 试图在SSIS中使用XML任务来加载一些值。 Using Microsoft' XML inventory mentioned below. 使用下面提到的Microsoft的XML库存。

How can I load first-name value in bookstore/books where style is novel and award = 'Pulitzer'? 如何在书店/书籍中加载名字价值的新颖和奖励='普利策'? //book[@style='novel' and ./author/award/text()='Pulitzer'] is what I am trying. //book[@style='novel' and ./author/award/text()='Pulitzer']正是我的尝试。 It gives the whole element. 它给出了整个元素。 Where should I modify to just get the first-name value? 我应该在哪里修改才能获得名字值?

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="myfile.xsl" ?>
<bookstore specialty="novel">
  <book style="autobiography">
    <author>
      <first-name>Joe</first-name>
      <last-name>Bob</last-name>
      <award>Trenton Literary Review Honorable Mention</award>
    </author>
    <price>12</price>
  </book>
  <book style="textbook">
    <author>
      <first-name>Mary</first-name>
      <last-name>Bob</last-name>
      <publication>Selected Short Stories of
        <first-name>Mary</first-name>
        <last-name>Bob</last-name>
      </publication>
    </author>
    <editor>
      <first-name>Britney</first-name>
      <last-name>Bob</last-name>
    </editor>
    <price>55</price>
  </book>
  <magazine style="glossy" frequency="monthly">
    <price>2.50</price>
    <subscription price="24" per="year"/>
  </magazine>
  <book style="novel" id="myfave">
    <author>
      <first-name>Toni</first-name>
      <last-name>Bob</last-name>
      <degree from="Trenton U">B.A.</degree>
      <degree from="Harvard">Ph.D.</degree>
      <award>P</award>
      <publication>Still in Trenton</publication>
      <publication>Trenton Forever</publication>
    </author>
    <price intl="Canada" exchange="0.7">6.50</price>
    <excerpt>
      <p>It was a dark and stormy night.</p>
      <p>But then all nights in Trenton seem dark and
      stormy to someone who has gone through what
      <emph>I</emph> have.</p>
      <definition-list>
        <term>Trenton</term>
        <definition>misery</definition>
      </definition-list>
    </excerpt>
  </book>
  <my:book xmlns:my="uri:mynamespace" style="leather" price="29.50">
    <my:title>Who's Who in Trenton</my:title>
    <my:author>Robert Bob</my:author>
  </my:book>
</bookstore>

我得到了答案。

//book[@style='novel' and ./author/award/text()='Pulitzer']//first-name

Use : 用途

/*/book[@style='novel']/author[award = 'Pulitzer']/first-name

This selects any first-name element whose author parent has a award child with string value of 'Pulitzer' and whose (of the author ) parent is a book whose style attribute has value "novel" and whose parent is the top element of the XML document. 这将选择其author父级具有award子项的任何first-name元素,其字符串值为“Pulitzer”且其( author )父级是一bookstyle属性的值为“novel”且其父级是XML的顶级元素文献。

A similar question in the same context. 同一背景下的类似问题。 How can I do the vice-versa ? 我怎么能反过来呢? Let's suppose I want to find the id of all those books whose price is greater than 20 ? 我想我想找到价格大于20的所有书籍的ID? I know I am being a nudge, but really want to clear my understanding. 我知道我是一个轻推,但真的想清除我的理解。

Here is the needed XPATH : 这是需要的XPATH

//book/price[text() > 20]/..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM