How to use multiple conditions in Xpath?

New to Xpath. There was an attempt to use an XML task in SSIS to load some values. Using the Microsoft XML Inventory, mentioned below.

How can I upload name-to-name in a bookstore / books where the new style and award = "Pulitzer"? //book[@style='novel' and ./author/award/text()='Pulitzer'] is what I'm trying. He gives the whole element. Where can I change to get only the name?

 <?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">BA</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 Who in Trenton</my:title> <my:author>Robert Bob</my:author> </my:book> </bookstore> 
+6
source share
3 answers

I got an answer.

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

Using

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

This selects any first-name element, the author parent has an award child element with the string value "Pulitzer" and whose ( author parent) is a book whose style attribute has the value "romance" and whose parent element is the top element of the XML document.

+5
source

A similar question in the same context. How can I do it the other way around? Suppose I want to find the identifier of all those books whose price is more than 20? I know that I'm pushing, but really want to clear my understanding.

Here is the required XPATH :

 //book/price[text() > 20]/.. 
+1
source

All Articles