6

Xpath 新手。试图在 SSIS 中使用 XML 任务来加载一些值。使用下面提到的 Microsoft 的 XML 清单。

如何在风格新颖且奖项=“普利策”的书店/书籍中加载名字值? //book[@style='novel' and ./author/award/text()='Pulitzer']是我正在尝试的。它给出了整个元素。我应该在哪里修改以获得名字值?

<?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>
4

3 回答 3

8

我得到了答案。

//book[@style='novel' and ./author/award/text()='Pulitzer']//first-name
于 2013-04-20T11:42:10.330 回答
5

使用

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

这将选择其父first-name元素具有字符串值为“普利策”的子元素且其(的)父元素为 a且其属性值为“novel”且其父元素为 XML 文档的顶部元素的任何元素。authorawardauthorbookstyle

于 2013-04-21T16:56:53.183 回答
1

相同上下文中的类似问题。我该怎么做,反之亦然?假设我想找到所有价格大于 20 的书籍的 id ?我知道我是在轻推,但我真的很想澄清我的理解。

这是需要的XPATH

//book/price[text() > 20]/..
于 2013-04-22T17:38:44.287 回答