XPath dnevnik

An XPath recipe list. See also Bibliographic XPath Queries and BaseX Adventures.

1. Find attributes by ends of their value strings

  • 2011-09-03
  • XPath 2.0
  • Find all attributes “ana” whose value ends with “exempla”
  • Expression (apply the forward slash abbreviation before @ana if necessary):

@ana[ends-with(.,”exempla”)]

2. Find a specific element and all of its descendants of the same kind

  • 2011-09-04
  • XPath 2.0
  • Find the “seg” element with the xml:id attribute value “E6.9.4”; also find all “seg” descendants of this element
  • Expression (add double forward slash before seg as needed):

seg[ancestor-or-self::seg[@xml:id[. eq 'E6.9.4']]]

3. Find all elements with attributes that contain a specific string

  • 2011-09-08
  • XPath 2.0
  • Find all elements with attribute ana whose value contains “MARK”
  • Expression (add double forward slash before @ana as needed):

@ana[contains(.,”MARK”)]

4. Retrieve all elements with specific attributes preceded by siblings with specific attributes

  • 2011-09-11
  • XPath 2.0
  • Find all seg elements with attribute ana whose value contains “MARK”, preceded by seg elements with attribute ana whose value contains “NORMAL”
  • Expression (add double forward slash before seg as needed):

seg[@ana[. eq 'MARK']][preceding-sibling::seg[@ana[. eq 'NORMAL']]]

5. Retrieve all elements with specific attributes immediately preceded by a sibling with specific attributes

  • 2011-09-12
  • XPath 2.0
  • Find all seg elements with attribute @ana whose value equals “PLANA”, immediately preceded by a seg element sibling with attribute @ana whose value contains “tekst”
  • Expression (add double forward slash before seg as needed):

seg[@ana[. eq 'PLANA']][preceding-sibling::seg[1][@ana[contains(.,'tekst')]]]

6. Find all elements with odd / even numeric values in attributes

  • 2011-12-2
  • XPath 2.0
  • Find all anchor elements with attribute @n whose value is an odd number
  • Expression (add double forward slash before seg as needed):

anchor[number(@n) mod 2 = 1]

 
z/xpath-dnevnik.txt · Last modified: 18. 06. 2012. 17:08 by njovanov
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki