Ho to Use multiple conditions in Xpath ?

  • Hi guys,

    New to Xpath. Was trying to use XML task to load some values. Using Microsoft' XML inventory mentioned below.

    How can I load values in bookstore/books where style is novel and award = 'Pulitzer' ?

    //book[[@style ='novel'] and @award [.= 'Pultizer']] is what I am trying and getting an error. Could you please explain where I am going wrong ?

    <?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>Pulitzer</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>

  • We can use the below condition if we want to find the first-name.

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

    Any better answer is deeply appreciated.Thanks for viewing my question though.

  • These are the nodes you are looking for...

    //book[@style="novel"]/author/award[.="Pulitzer"]/../..

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]

  • Thank you for your suggestion. How can I do the vice-versa ?

    I mean I would like to find which style of book is it whos author has won the "Pulitzer prize" ??

  • This gets you the books...

    //book/author/award[.="Pulitzer"]/../..

    Then you just need to extract the @style,@id attributes etc... from those book nodes

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]

  • that was the question. I am not able to extract those values.

    It's like finding parent id depending on child conditions.

    //book/author/award[.="Pulitzer"]/style doesn't work as exepcted. Could you please tell the exact path to find the style of the book.

  • I got the solution but it needs some modification:

    I am able to get those values using ancestor keyword but the result is coming out as a concatenate.

    Result now : Noveltextbook

    Desired :

    Novel

    texbook

    How can I introduce [CR][LF] in between ?

  • connect.akshay (4/22/2013)


    I got the solution but it needs some modification:

    I am able to get those values using ancestor keyword but the result is coming out as a concatenate.

    Result now : Noveltextbook

    Desired :

    Novel

    texbook

    How can I introduce [CR][LF] in between ?

    What are you trying to do? You have posted this in the Integration Services forum, but are now talking about formatting output?

    Also, perhaps you could show us what you are doing to get the result you have now? We can't see what you see!

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]

  • MM

    The forum is correct. I was using an XML task in SSIS. My requirement was the earlier one where I wanted to find the First-name.

    I thank you for your answer. But just for my knowledge sake I asked the second question about the vice versa and it's answer in a formatted way.

    Apologies if you got confused.

  • I wasn't able to upload the screenshot here. So created another thread. Please see ..

    http://stackoverflow.com/questions/16161774/xpath-find-parent-attribute-using-child-condition

  • Viewing 10 posts - 1 through 9 (of 9 total)

    You must be logged in to reply to this topic. Login to reply