xpath

Bind to specified XML-element

In short: I want to define what XML ButtonSettings element to use for a XAML-Button, and to use the childs of the selected ButtonSettings-element in a style applied to that Button. Is this possible? A sample of the XML: <Buttons> <ButtonSettings ID="Bye"> <Text lang="NL">Doei!</Text> <Text lang="DE">Tsusch!</Text> <Tex...

How do I generate a comma-separated list with XSLT/XPath?

Given this XML data: <root> <item>apple</item> <item>orange</item> <item>banana</item> </root> I can use this XSLT markup: ... <xsl:for-each select="root/item"> <xsl:value-of select="."/>, </xsl:for-each> ... to get this result: apple, orange, banana, but how do I produce a list where the last comma is not present? ...

Custom XPath in MySQL

I'm wondering if anyone out there as built a custom script or stored procedure that will accept a field and an XPath expression to return. Even if it's really clumsy, I'll take it. Something like this: FindByXPath(fieldName, query); Which I would give values: FindByXPath([xmlContent], '/root/customer/country[@attribute]'); All I ...

Can I validate an XPath expression against an XML schema?

You can verify an XPath expression against an XML doc to verify it, but is there an easy way to verify the same XPath expression against the schema for that document? Say I have an XSD schema like this: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ... etc> <xsd:element name="RootData"> <xsd:complexType> <xsd:seq...

xPath Traversing

I am trying to use xPath to traverse through the code of a newspaper (for the sake of practice) right now I'd like to get the main article, it's picture and the small description I get of it. But I'm not that skilled in xPath so far and I can't get to the small description. withing this code: <div class="margenesPortlet"> <div class="...

How not to copy some attributes?

I need to copy from input document to output document all attributes but one. My input is like this: <mylink id="nextButton" type="next" href="javascript:;" /> And I need output like this: <a id="nextButton" href="javascript:;" /> If I use the following XSL: <xsl:template match="mylink"> <a><xsl:copy-of select="attribute::*"/...

XSLT filter with an index counter

I've written some XSLT that uses one XML document to filter another. Now I'd like to number my output elements using position(), but my filtering condition is not built in to my <xsl:for-each>, so position() gives me results with numbering gaps. How do I get rid of the gaps? <xsl:variable name="Astring"> <a><b>10</b><b>20</b><b>30</b>...

How to Iterate Over Unknown Columns in XSLT

Hi .... The Title pretty much says it all. I have an XML document that I am processing with XSLT .... but I don't know how many columns (fields) that are in the XML document (therefore, obviously, I don't know their names). How can I determine the number of "unknown" fields there are? Also, how can I read the attributes, if any, for ...

Getting all nodes between the current node and another without current()?

I'm working on a Greasemonkey script which needs to operate on each node between two others. Currently, I'm getting the first node using an (increasingly-complicated) XPath expression. I have another expression to get the "between" nodes, but it contains the initial expression twice and is getting rather long. Here's an earlier versio...

need help with Selenium and xPath selectors

I'm trying to automate testing of the code... well, written without testing in mind (no IDs on many elements, and a lot of elements with the same class names). I would appreciate any help (questions are below the code): <div id="author-taxonomies" class="menu-opened menu-hover-opened-inactive" onmouseover="styleMenuElement(this)" onmous...

Is there an online tester for xPath selectors?

I know there are some online regex evaluators.. very useful, matching in real time. They are like web applications of RegexBuddy. I was wondering if there is a similar thing for xPath selectors? I am just learning them and it would be valuable to me. Is there an online tester that allows you to input XML and then an xPath selector and ...

Is XPath much more efficient as compared to DOM and SAX?

I need to parse an xml string and find values of specific text nodes, attribute values etc. I'm doing this in javascript and was using the DOMParser class for the same. Later I was informed that DOM is takes up a lot of memory and SAX is a better option. Recently I found that XPath too provides a simple way to find nodes. But I'm not ...

How do I reference the 'next' (as yet nonexistant) XML node in a sequence?

So to expand... I have some XML <root> <list> <item value="9"/> <item value="3"/> <item value="1"/> <item value="8"/> <item value="4"/> </list> </root> I have an XPath "/root/list/item [4]" which I believe will retrieve the 5th 'item' element (whose value attribute is 4) This suggest...

What is the proper XPath for "all nodes exactly one below the base node?"

Presuming that I don't know the name of my base node or its children, what is the XPath syntax for "all nodes exactly one below the base node?" With pattern being an XmlNode, I have the following code: XmlNodeList kvpsList = pattern.SelectNodes(@"//"); Which looks right to me, but I get the following exception: System.Xml.XPath.X...

Why does my XPath expression in Java return too many children?

Hello I have the following xml file: <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <config> <a> <b> <param>p1</param> <param>p2</param> </b> </a> </config> and the xpath code to get my node params: Document doc = ...; XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile("/c...

XPath: select all A nodes and all B nodes that are not inside an A node

Is the following possible in one XPath expression (see sample below): Select all (span tags of class msg) AND all ((img tags that have a non-empty alt attribute) AND (are NOT located inside a span tag of class msg)) Simplified sample: <span class="msg">Message text A</span> <img alt="" /> <span class="msg">Message text B <img alt="te...

XPath 1 query and attributes name

First question: is there any way to get the name of a node's attributes? <node attribute1="value1" attribute2="value2" /> Second question: is there a way to get attributes and values as value pairs? The situation is the following: <node attribute1="10" attribute2="0" /> I want to get all attributes where value>0 and this way: "attr...

xpath selection on elements with namespaces

Here's a trivial but valid Docbook article: <?xml version="1.0" encoding="utf-8"?> <article xmlns="http://docbook.org/ns/docbook" version="5.0"> <title>I Am Title</title> <para>I am content.</para> </article> Here's a stylesheet that selects title if I remove the xmlns attribute above, and not if I leave it in: <?xml version="1.0" en...

Basics of XmlNode.SelectNodes?

I'm not sure why this isn't working. I have an XmlNode in a known-format. It is: <[setting-name]> <dictionary> <[block-of-xml-to-process]/> <[block-of-xml-to-process]/> <[block-of-xml-to-process]/> </dictionary> </[setting-name]> I have a reference to the node in a variable called pattern. I want an itera...

PHP: Check if XML node exists with attribute

I can't seem to figure this one out. I have the following XML file: <?xml version="1.0" encoding="UTF-8"?> <targets> <showcases> <building name="Big Blue" /> <building name="Shiny Red" /> <building name="Mellow Yellow" /> </showcases> </targets> I need to be able to test whether or not a <building> node exists with a ...