xpath

Find the maximum child count with XPath 1.0

Can I find one XML node with the most children with XPath? <xml> <node id="1"> <child /> <node> <node id="2"> <child /><child /> <node> <node id="3"> <child /><child /> <node> <node id="4"> <child /><child /><child /> <node> <node id="5"> <child /><child /><child /> <node> </xml> I would like to...

How to get equivalent of max() on MSXML6?

Evidently MSXML6 doesn't support XSLT 2.0, at least not the max() function. I need to find out the node that contains the highest value among its siblings. They are in arbitrary order. I want the order to remain identical so adding order-by and checking [0] is out of question. I want to do this with a single XPath statement. I don't wa...

XPath format-number with number of decimal places based on a variable?

I have an XML document where the number of decimal places a particular xs:decimal should be reported in is held in a sibling node. I'm currently struggling to find a simple way to output this via the format-number function. I can build a picture string with some other functions, but this seems terribly long-winded for what should be (at...

Xpath contains certain word

How can I use Xpath to only select the all dict's that contain genre? <dict> <key>genre</key><string>News</string> <key>genreId</key><integer>6009</integer> </dict> <dict> <key>fieldID</key><integer>2</integer> </dict> ...

XPath: Parent form of submit button

I want to use PHP and DomXPath::query to get the parent "form" element of a submit button. The variable $dom holds the complete DOM tree and $node represents the submit button as a DOM node. $query = '??????'; $xpath = new \DomXPath( $dom ); $parents = $xpath->query( $query, $node ); if ( $parents->length ) { $form = $parents->it...

Is there a way to get a node value with xPath without this ugly somersault?

This is a java question, btw. I'm using xPath and everything works great until I get to the last point where I'm looking at the node set that I've sought and I need to do a really ugly evaluation to see if the node I'm dealing with is of type ELEMENT or TEXT before I can get its value. I was wondering if there's a method along the line...

duplicate selection in text() XPath selector

I'm trying to select all nodes with text that contain a certain word (ex: Company) because the word needs to have a register mark. Here is part of the XHTML (this <p> is inside a table cell). <p> <strong> <a style="color:#0E5A8B; text-decoration:none" target="_blank" href="http://www.trekk.com"&gt; <span class="title"> ...

Can find descendants using LINQ to XML or XPath Extensions

Anyone knows the problem why linq to xml or xpath extensions cant seem to read this xml? http://www.quillarts.com/Test/product.xml var document = XDocument.Load(feedUrl); var xpathxml = from feed in document.XPathSelectElements("//Products") //using Xpath var linqtoxml = from feed in document.Descendants("Products") //using Linq2XML ...

Problem Reading XElement Attribute

Anyone knows why this xpath expression "catzero/@id" is not working on this xml document = XDocument.Load("file.xml"); var product = document.XPathSelectElements("//product", nameSpaceResolver).First(); var category = ((IEnumerable) product.XPathEvaluate("catzero/@id")).Cast<XAttribute>().first().value; //catezero/@id is null ...

How can I access attributes and elements from XML::LibXML in Perl?

I am having trouble understanding / using name spaces with XML::LibXML package in Perl. I can access an element successfully but not an attribute. I have the following code which accesses an XML file (http://pastebin.com/f3fb9d1d0). my $tree = $parser->parse_file($file); # parses the file contents into the new libXML object. my $xpc =...

Can't Get .NET XPathNavigator to work

I am having problems with XPathNavigator. I have a document with a bunch of "topic" elements w/o namespace in a stream. I am using (expression dumbed down to bare minimum, first I thought my expressions were wrong): XPathDocument xmlDoc = new XPathDocument( stream ); XPathNavigator xml = xmlDoc.CreateNavigator(); XPathNodeIterator iter...

How do you specify node result order using XPath?

I have the following XML, which is generated by a 3rd-party library: <PhoneNumbers> <PhoneNumber Key="1">123-456-7890</PhoneNumber> <PhoneNumber Key="2">234-567-8901</PhoneNumber> <PhoneNumber Key="3">345-678-9012</PhoneNumber> </PhoneNumbers> The issue is that I should not depend on the values of the Key attribute (a) appe...

Nodes sequence with options values

Here's a question about repeated nodes and missing values. Given the xml below is there a way in XPath of returning (value2, null, value5) rather than (value2, value5)? I'm using an expression that looks like: /nodes/node[*]/value2/text() To retrieve the values. I need to know there's a value missing and at which indexes this occurs....

Unique ID and multiple classes with XPath

Hi I'm using XSLT for displaying a ul menu containing li and a. I want the following: Find the first li a element and add the .firstitem class. Find the last li a element and add the .lastitem class. Find the active li a element and add the .active class. Add an unique ID to each li a element. (I.e. URL friendly menu text as ID). I...

Jaxen /text() not working

I have the html: <p> <a href="#">click here</a> Welcome </p> And I just want to retrieve the "Welcome" part using Xpath combined with the Jaxen lib the Xpath I am using is; //p/text() Now when I remove the /text() it retrieves; click here Welcome With the /text() added it retrieve null Is there any other way to retrieve everythi...

Can YQL parse web sites requiring cookie-based authentication?

First, my use case: I'm trying to use YQL's built in XPATH capabilities to scrape content from Yahoo! Fantasy Sports. It uses some sort of cookie-based authentication scheme. Basically, the sequence is: 1) Do an HTTP GET on the Yahoo! Login page 2) Parse the hidden inputs from the response and do an HTTP PUT with your Yahoo! Login on t...

Casting an Integer to a Double in XPath 1.0

I am currently building a XML based Jasper Report in which I am trying to add a tax percent onto the cost. A problem occurs when I use sum(//net-total) to value calculate the total cost. When the summed total has no decimal places it returns and Integer and I need a double. I have tried sum(//net-total) * 1.0 but it doesn't seem to wor...

Set difference with XPath 1.0 - how do I get .//table without .//table//table?

I'm trying to find all the tables below my current node without also including the nested tables. In other words, if I have this, i want to find "yes" and not "no": <table> <!-- outer table - no --> <tr><td> <div> <!-- *** context node *** --> <table> <!-- yes --> <tr><td> <table> ... </table> <!-- no --> ...

XPath: Query an attribute from a nodeset in a variable

Within an XSL sheet, I have a nodeset in a variable, $context. How do I properly query an attribute of the topmost node in $context? Obviously, if $context was the current node, I would just write "@attname", but it is not. Currently I do $context/../@attname which is doesn't look great to me. EDIT Ok, the data. Here is what I see in ...

XPath: Selecting nodes included by an <xsl:include>

There's an XSL that includes another XSL: <xsl:include href="registered.xsl"/> That included file has a list of nodes: <g:registered> <node1/> <node2/> </g:registered> Documentation says that "the children of the <xsl:stylesheet> element in this document replace the element in the including document", so I would think that, gi...