Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. How to match several different elements in the middle of XPath?

How to match several different elements in the middle of XPath?

Scheduled Pinned Locked Moved XML / XSL
xmlsharepointregextutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CherezZaboro
    wrote on last edited by
    #1

    Consider this xml: <rrx id="someother">...</rrx> <rrx id="Zones"> <f name="NM"> <p name="xoxoxo"/> </f> <s name="GB"> <p name="xexexe"/> <p name="xaxaxa"/> </s> <a name="SP"> <p name="hmhmhm"/> </a> <b name="Alien"> <p name="opsops"/> </b> </rrx> I need to select all "p" elements in "f","s" or "a" with a given "name" but not "b" which are in "rrx" with particular "id". So I'm trying to come up with or statement for f,s,a in the middle of XPath. Using XSLT 2.0 and Xpath 2.0 this works fine: //rrx[@id='Zones']/(f|s|a)[@name='GB']/p - I should get xexexe and xaxaxa and if //rrx[@id='Zones']/(f|s|a)[@name='SP']/p - I need hmhmhm But good old 1.0 says it's invalid. That () are not allowed there. How else would the XPath then look? :omg: :zzz: :doh:

    E 1 Reply Last reply
    0
    • C CherezZaboro

      Consider this xml: <rrx id="someother">...</rrx> <rrx id="Zones"> <f name="NM"> <p name="xoxoxo"/> </f> <s name="GB"> <p name="xexexe"/> <p name="xaxaxa"/> </s> <a name="SP"> <p name="hmhmhm"/> </a> <b name="Alien"> <p name="opsops"/> </b> </rrx> I need to select all "p" elements in "f","s" or "a" with a given "name" but not "b" which are in "rrx" with particular "id". So I'm trying to come up with or statement for f,s,a in the middle of XPath. Using XSLT 2.0 and Xpath 2.0 this works fine: //rrx[@id='Zones']/(f|s|a)[@name='GB']/p - I should get xexexe and xaxaxa and if //rrx[@id='Zones']/(f|s|a)[@name='SP']/p - I need hmhmhm But good old 1.0 says it's invalid. That () are not allowed there. How else would the XPath then look? :omg: :zzz: :doh:

      E Offline
      E Offline
      Erik Molenaar
      wrote on last edited by
      #2

      The feature you try to use is new to XPath 2.0 One of the ways you could solve it in XPath 1.0 would be: instead of: //rrx[@id='Zones']/(f|s|a)[@name='SP']/p write: //p[(parent::f[(@name='SP')and(parent::rrx[@id='Zones'])]) or (parent::s[(@name='SP')and(parent::rrx[@id='Zones'])]) or (parent::a)[(@name='SP')and(parent::rrx[@id='Zones'])]] It does not look nice, but would be an example.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups