Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Ho to Use multiple conditions in Xpath ? Expand / Collapse
Author
Message
Posted Saturday, April 20, 2013 1:56 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 1, 2014 6:20 AM
Points: 19, Visits: 172
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>

Post #1444690
Posted Saturday, April 20, 2013 5:48 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 1, 2014 6:20 AM
Points: 19, Visits: 172
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.
Post #1444703
Posted Saturday, April 20, 2013 9:49 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 5:36 PM
Points: 1,816, Visits: 5,916
These are the nodes you are looking for...

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



MM


  • MMGrid Addin
  • MMNose Addin


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

  • Post #1444718
    Posted Monday, April 22, 2013 5:05 AM
    Grasshopper

    GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

    Group: General Forum Members
    Last Login: Wednesday, October 1, 2014 6:20 AM
    Points: 19, Visits: 172
    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" ??



    Post #1444923
    Posted Monday, April 22, 2013 5:23 AM


    SSCommitted

    SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

    Group: General Forum Members
    Last Login: Today @ 5:36 PM
    Points: 1,816, Visits: 5,916
    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


  • MMGrid Addin
  • MMNose Addin


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

  • Post #1444927
    Posted Monday, April 22, 2013 6:38 AM
    Grasshopper

    GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

    Group: General Forum Members
    Last Login: Wednesday, October 1, 2014 6:20 AM
    Points: 19, Visits: 172
    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.
    Post #1444953
    Posted Monday, April 22, 2013 7:00 AM
    Grasshopper

    GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

    Group: General Forum Members
    Last Login: Wednesday, October 1, 2014 6:20 AM
    Points: 19, Visits: 172
    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 ?
    Post #1444964
    Posted Monday, April 22, 2013 7:30 AM


    SSCommitted

    SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

    Group: General Forum Members
    Last Login: Today @ 5:36 PM
    Points: 1,816, Visits: 5,916
    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


  • MMGrid Addin
  • MMNose Addin


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

  • Post #1444981
    Posted Monday, April 22, 2013 8:39 AM
    Grasshopper

    GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

    Group: General Forum Members
    Last Login: Wednesday, October 1, 2014 6:20 AM
    Points: 19, Visits: 172
    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.
    Post #1445012
    Posted Wednesday, April 24, 2013 10:59 PM
    Grasshopper

    GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

    Group: General Forum Members
    Last Login: Wednesday, October 1, 2014 6:20 AM
    Points: 19, Visits: 172
    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
    Post #1446292
    « Prev Topic | Next Topic »

    Add to briefcase

    Permissions Expand / Collapse