xpath

xslt: time ago test

using xslt how do i test if a date was within the last (say) 15 days? input: date in format dd/mm/yy X number of days output: if the date occured within X days of now eg recent('02/07/10',30) would return true iff 02/07/10 was 30 days in the past some steps i got: main func <xsl:function name="custom:monthtodays"> <x...

How to get a HTML element by text using XPath?

Hello! I'm encoutered a problem that is could not get a HTML element by element's text.My HTML looks like: ... <table> ... <tr> ... <td class="oMain">test value</td> ... <tr> ... </table> ... For some special reasons,I have to get the '<td class="oMain">' element using it's text 'test value'. I tried '//tr[td='tes...

XML Design and Name Reuse - Is it Good or Bad for Elements of Different Types to Have the Same Name?

When designing an XML structure I sometimes find myself wanting to use similar patterns across multiple element types that appear in the same instance document. For example, the Head-Body pattern can often be useful if you want to keep data and meta data (data about the data) separate, and sometimes it makes sense for multiple types of ...

Xpath - How to get the data contained between elements, not the elements themselves

I'm writing a Java program that scrapes a web page for links and then stores them in a database. I'm having problems though. Using HTMLUnit, I wrote the following: page.getByXPath("//a[starts-with(@href, \"showdetails.aspx\")]"); It returns the correct anchor elements, but I only want the actual path contained in the href attribute, n...

Convert Xpath expression for all nodes from XML file/XML document

Hi, I have a requirement to get XPath expression for all xml nodes in .NET. Do we have any tools or API that generates XPath for every xml node. for ex. <ACORD> <foo> <bar>1</bar> </foo> <testnode>2</testnode> </ACORD> the output will be /ACORD /ACORD/foo /ACORD/foo/bar /ACORD/testnode ...

XPath and namespaces

Hello, I have xml like below <ns:response xmlns:ns="http://example.com" xmlns:ax="http://example.com/xsd" > <ns:return type="mytype"> <ax:roleID>1</ax:roleID> <ax:roleName>ADM</ax:roleName> </ns:return> <ns:return type="mytype"> <ax:roleID>2</ax:roleID> <ax:roleName>USR</ax:roleName> </ns:...

Optimal method to store XPath definitions.

I know how to use XPath, but often wondered what is the optimal way to store then during runtime. In the past i've split them up into individual bits, stored them as character strings, and one or two other ways. Now I have a configuration file with bundles of them, like twisted knots, and am now looking for the optimal way to store them...

How to get Atomic Value between Element Nodes using XPath

I want to select only the atomic values inside a node. For example, the "here" text in the following: <a href="">here</a> When I use Xpath in Java, it returns some sort of object/array, such as [DomNode[<a href="">here</a>]] I just want the text only. Is this possible, and how? Thanks! ...

Dynamic grouping on element and attributes names

Hi! I would like to categorize results from an XPath under headings by element name (and then by same attribute names). Note: XML data could be inconsistent and some elements with the same name could have different attributes, therefore they need different headings. I can't seem to write out my problem in words, so it might be best to...

XPath check for non existing node

Hi, Im having a bit of trouble finding the right XPath syntax to check if a particular node in my xml exists. I'm only allowed to use XPath (so no XSL or something else like that, it has to be a pure XPath expression syntax). I have an xml and it has a node "Filename" but it doesn't exist in every case. When the filename isn't specifi...

Why do indexes in XPath start with 1 and not 0?

Some colleagues and I were comparing past languages we had programmed in and were chuckling about our experience with VBScript with its odd features such as 1-based index instead of 0-based indexes like almost every other language has, the reasoning being that it was a language for users (e.g. Excel VBA) instead of a language for develop...

How to know when to cast to an Xelement or XAttribute?

I have a situation where an end user can enter an XPath to access a value in some XML. I’m using a line of code similar to the one below: IEnumerable e = (IEnumerable)importDocument.XPathEvaluate(theXPath); As the Xpath could return an Attribute or an Element, what I need to know is how can I interpret ‘e’ in the above example to deci...

how to for every parent node select every not first child node in a tree with multiple parent nodes

His, I think I've got a tricky questions for XPath experts. There is a node structure like this: A(1)-| |-B(1) |-B(2) |-B(3) A(2)-| |-B(2.1) |-B(2.2) |-B(2.3) ... How to, with a single XPath-expression, extract only the following nodes A(1)-| |-B(2) |-B(3) A(2)-| |-B(2.2) |-B(2.3) ...

How to match certain text in returned XPath HTML?

I am using Xpath in Ruby with following statement. print XPath.first(Document.new(html),"//tr[@id='ctl00_c1_rr_ci_trAdd']//td[2]") The Query return the following text. <td> 1371 N Belsay Rd<br/>Burton, MI 48509 <br/> <a href='http://www.mapquest.com/maps/map.adp?style=2&amp;amp;addres...

XPath: match multiple elements in one expression

Hi, I'm trying to do this (using lxml): //*[@id="32808345" or @id="33771423" or @id="15929470" or @id="33771117" or @id="15929266"] in order to get all elements, no matter what tag, with the specified id's. I'm getting the following traceback: invalid attribute predicate this is how I'm generating the str (if that is relevant to t...

How can I select the first element of a node with XSL?

I'm coding my first website using XML+XSL. The xml I am transforming have this section: <page> <news> <highlights> <entry> <mini>x_thumb.jpg</mini> <title>title</title> <text>text</text> <image>x.jpg</image> <link>x.html</link> ...

In XPath 1.0, how can I test whether a string with length 1 falls between two others codepoint-wise?

Given a document containing these tags, how can I tell whether " " < "H" < "z" in the document's encoding? I'm trying to do this in XPath 1.0. <text>H</text> <range> <from>&#x20;</from> <to>z</to> </range> I might even be able to get away with using contains(), but then how would I create a string containing the characters from "...

Question in Chrome Extensions Sample

Can anyone explaing me this line in detail? // Find all the RSS link elements. var result = doc.evaluate( '//*[local-name()="rss" or local-name()="feed" or local-name()="RDF"]', doc, null, 0, null); Best Regards, Cetin ...

Problem with XSLT getting values from tags with namespace prefixes

I have a specific problem getting values for width and height out of some XML that has namespace prefixes defined. I can get other values such as SomeText from RelatedMaterial quite easily using normal xpath with namespace "n:" but unable to get values for width and height. Sample XML: <Description> <Information> <GroupInformation xml:...

xpath/dom/term question

trying to get my head around a problem, not sure if there really is a solution, or a solution that's readily available. i'm trying to figure out if i can specify a "term" that's in the source of a webpage, and have the "blackbox" produce a fully qualified XPath for the DOM element that contains/has/uses the "term" in other words, if i h...