Menu
  • HOME
  • TAGS

XPath: Collecting while aggregating issue

xml,xpath,xpath-2.0

This is one place where you can use the for $me in . idiom: //person[count(for $me in . return //tree[ @height <= ($me/@height + 10) and @height >= ($me/@height - 10)]) >= 3] Here I'm using a single-iteration for expression to capture the current person (the . of the first-level...

How to getText() of particular links - Selenium Webdriver - TestNG? [closed]

xpath,selenium-webdriver,testng,xpath-2.0

Try below code: import java.io.IOException; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class Sample { WebDriver driver; @BeforeClass public void BeforeClass() throws InterruptedException, IOException { driver = new FirefoxDriver(); driver.manage().window().maximize();...

Modifying XPath 2.0 result trees using Saxon

saxon,xpath-2.0

I think you can supply a DOM node to Saxon and run XPath against it but it that case you don't use the document builder for Saxon's native trees, you build a DOM using the javax.xml.parsers.DocumentBuilder and once you have a W3C DOM node you can supply it to Saxon...

Xpath - extract only numbers

xpath,xml-parsing,google-spreadsheet,google-docs,xpath-2.0

try extracting the digits with regexextract and see if that works ? =REGEXEXTRACT(IMPORTXML(J2; "//*[@id='tab-1411393574769-10']/div[2]/div/table[1]/tbody/tr[2]/td[2]"); "(\d+)") ...

How to insert nodes after specific node of an instance in Orbeon?

orbeon,xforms,xpath-2.0

What you are doing looks about right. But in your instance examRelatedNodes, you need to have a root element, say: <xf:instance id="examRelatedNodes"> <RelatedNodes> <ExamTitle/> <ExamDescription/> </RelatedNodes> </xf:instance> And then your insert will become: <xf:insert context="." origin="instance('examRelatedNodes')/*"/> ...

How I can count distinct-values with xslt and XPath 2.0

xml,xslt,xpath-2.0

With XSLT 2.0 it is a grouping problem to be solved with for-each-group: <xsl:template match="/"> <articles> <xsl:for-each-group select="//articles/article" group-by="articlenumber"> <xsl:copy> <xsl:copy-of select="* except amount"/> <amount><xsl:value-of select="sum(current-group()/amount)"/></amount> </xsl:copy> </xsl:for-each-group> </articles> </xsl:template> See http://xsltransform.net/3NzcBt8 for a complete sample....

XQuery/XPath LIMIT a sum

xpath,xquery,xpath-2.0,xquery-3.0

You can use fn:max() function as follow: fn:max( for $pair_ids in distinct-values(fn:doc("tourny.xml")/Competition[@date = "2012-12-12"]/Tennis/Partner/@pair_id) let $total_scores := sum(fn:doc("tourny.xml")/Competition[@date = "2012-12-12"]/Tennis/Partner[@pair_id = $pair_ids]/@score) order by $total_scores descending return $total_scores ) ...

Can I get the sign of the number using xpath

xpath,xpath-2.0

Use this XPath 2.0 expression: '+'[$x ge 0], '-'[$x lt 0] where $x is the number, whose sign is wanted. This is shorter and might be slightly more efficient (having only a single comparison): ('+'[$x ge 0], '-')[1] Use this XPath 1.0 expression: substring('+-', 2 - ($x >= 0), 1)...

XPath: Query a node's children XOR a subnode's children if subnode is present

xpath,xpath-2.0

First, two XPath 1.0-compatible examples: You could do so like this: (/parent/container/a[not(b)] | /parent/container/a/b)/* Or to use the double-slash syntax (which I would recommend avoiding unless the paths are really long): (//a[not(b)] | //a/b)/* But since your question is tagged with XPath 2.0, the following would probably be more efficient...

XSLT 2.0: Rounding result of calculation to two decimals

xslt,rounding,xslt-2.0,xpath-2.0,rounding-error

How about: <xsl:value-of select="format-number(Price * Quantity, '0.00')"/> Note also that I get the same - expected - results with all of these: <xsl:value-of select="round(Price * Quantity * 100) div 100" /> and: <xsl:value-of select="round(xs:decimal(Price) * xs:decimal(Quantity) * 100) div 100" /> and: <xsl:value-of select="round(xs:decimal(Price) * xs:decimal(Quantity) * 10 * 10)...

XPath expression - or not working as expected

java,xpath,xpath-2.0

Well, it is a pretty confusing expression. //*[local-name() = 'manifestation' and *[local-name() = 'extension']/*[local-name() = 'manifestation_type'] = 'fmx4' and *[local-name() = 'reference_manifestation']/@format[. != 'TIFF' and . != 'FMX4']] In plain English, line for line: Look for elements anywhere in the document, if their local name is "manifestation". Also, there must...

xpath for the below code?

xml,xpath,xpath-2.0

Based on our interchange in the comments you are looking for the expression //fldChar[@fldCharType="end"][some $it in //instrText[@xml:space = "preserve"] satisfies count(./ancestor::node()) eq count($it/ancestor::node())]. Or a bit shorter //fldChar[@fldCharType="end"][some $it in //instrText[@xml:space = "preserve"] satisfies count(ancestor::node()) eq count($it/ancestor::node())].

xpath query conditional test comparing 2 numeric values

xml,xslt,xpath,xpath-2.0,xpathquery

In the query test="(count(//a) > 0)" test refers to a child element of the document node called "test". If there is no such element (which is the case here), then you are comparing an empty set to the string "count(//a) > 0". Comparing an empty set to anything returns false....

Select nodes containing a child with a class that contains X

xml,xpath,xml-parsing,xpath-2.0

You want //a[.//div[contains(@class, 'subject')]] The contains() function only takes the first item in its first argument, so if you pass .//div/@class as the first argument to contains(), you will only be testing the first result of .//div/@class instead of testing all of them. In other words, the code you tried...

How to select nodes with conditions based on attributes

xml,xslt,xpath,xslt-2.0,xpath-2.0

I would do the grouping and sorting in XSLT 2.0, if you want to have that then available in XPath you could write a user-defined function wrapping the functionality: <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mf="http://example.com/mf" exclude-result-prefixes="xs mf"> <xsl:output indent="yes"/> <xsl:function name="mf:group-and-sort" as="element(elementA)*"> <xsl:param name="input" as="element(elementA)*"/> <xsl:for-each-group...

Xpath for finding element that does not have sibling

html,dom,xpath,xpath-2.0

Just negate the condition: //a[@class="ahrefclass"][not(../span[@class="evilspan"])] which is, in this case, equivalent to //a[@class="ahrefclass" and not(../span[@class="evilspan"])] ...

sequence (XPath 2.0) vs nodeSet (XPath 1.0)

xpath,xpath-2.0

Firstly, the only kind of collection allowed in XPath 1.0 was a collection of nodes. XPath 2.0 also allows collections (sequences) of strings, numbers, and so on. Without this, functions such as tokenize() or string-to-codepoints() are impossible. Secondly, having only sets rather than sequences means you can't do things like...

XPATH for combining multiple identical entries

xml,xpath,xpath-2.0

XPath 2.0: string-join(.//Author/LastName, ', ') run it in the right context, for example per <Publication>....

XPath 2.0: How to implement a map/hash/associative_array

xpath,map,hashmap,associative-array,xpath-2.0

Several proposals: Probably the most reasonable way would be to put the data into some XML document with a key/value pairing and just query this document. An obvious, but rather hacky-ish solution would be to use string manipulation, eg. substring-after(('key1:val1', 'key2:val2')[starts-with(concat($key, ':'))], ':') Using index-of. In XQuery, you would do...

XPath 2.0: Find all descendants matching criteria X, but with no ancestor matching criteria Y

xml,xpath-2.0

Use this XPath 1.0 expression: //*[@itemprop and not(ancestor::*[parent::* and @itemscope])] This selects all elements with an itemprop attribute that don't have an ancestor with an itemscope attribute, that (this ancestor) has a parent element (this means it isn't the document-element itself). In order to verify the exactly the wanted elements...

How to group heading level in XSL

xslt,xpath,xslt-2.0,xpath-2.0

This stylesheet uses XSLT 2.0 and was adapted from Michael Kay's XSLT 2.0 and XPath 2.0 Programmer's Reference.pdf, page 341-342. When the stylesheet below is applied to your input XML (I have added a root node named root to your example input XML): <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:strip-space...

How to transform change comment using xslt

xml,xslt,xslt-2.0,xpath-2.0

You can use the following XSLT: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@* | *"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="text()[contains(.,'α-index')]"> <xsl:value-of select="replace(., 'α-index', 'index 1')"/> </xsl:template> <xsl:template match="comment()">...

xslt 2.0 group-starting-with by element contents

xml,xslt,xpath,xslt-2.0,xpath-2.0

You need to match on group-starting-with="row[normalize-space(person)]" <xsl:template match="/"> <contacts> <xsl:for-each-group select="rows/row" group-starting-with="row[normalize-space(person)]"> <contact> <xsl:copy-of select="person"/> <numbers> <xsl:copy-of select="current-group()/tel"/> </numbers> </contact> </xsl:for-each-group> </contacts> </xsl:template> ...

Xpath2.0 selecting first and last occurance of string with iteration

xml,xpath,xpath-2.0

In XSLT 2.0 this would be easy with for-each-group, grouping by the 200 value and taking the first and last members of each group. But in pure XPath (not XSLT) you need to think laterally. If the groups are always contiguous as you've shown here (i.e. all the ABC1234 entries...

XPath Query to get the tag and tag

html,xml,xpath,xpath-2.0,domxpath

Assuming that your HTML is well-formed, the following XPath will select all a elements: //a Just the first a: (//a)[1] Just the first a within the div whose @id is page: (//div[@id='page']//a)[1] You can equally easily apply these concepts to selecting b. Update The following XPath will select all a...