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. XPath: Select all nodes that DON'T contain certain subnodes

XPath: Select all nodes that DON'T contain certain subnodes

Scheduled Pinned Locked Moved XML / XSL
xmltutorial
3 Posts 2 Posters 5 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.
  • V Offline
    V Offline
    VizOne
    wrote on last edited by
    #1

    Hi! I need to select certain nodes that DON't have specific subnodes, i.e. Select all nodex x/y where there is no subnode x/y/a or x/y/b Example: blup test bla bla I'd appretiate all suggestions. Thanks in advance! Regards, Andre Loker

    M 1 Reply Last reply
    0
    • V VizOne

      Hi! I need to select certain nodes that DON't have specific subnodes, i.e. Select all nodex x/y where there is no subnode x/y/a or x/y/b Example: blup test bla bla I'd appretiate all suggestions. Thanks in advance! Regards, Andre Loker

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi Andre. Here's one approach - using a for-each to select only those x/y nodes that don't have a child a or child b node.

      <?xml version='1.0' ?>
      <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
      <xsl:template match="/">
      <xsl:for-each select="x/y[not ((descendant::a) or (descendant::b))]">
      <xsl:value-of select="."/>
      </xsl:for-each>
      </xsl:template>
      </xsl:stylesheet>

      I hope that helps.

      V 1 Reply Last reply
      0
      • M Mike Ellison

        Hi Andre. Here's one approach - using a for-each to select only those x/y nodes that don't have a child a or child b node.

        <?xml version='1.0' ?>
        <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
        <xsl:template match="/">
        <xsl:for-each select="x/y[not ((descendant::a) or (descendant::b))]">
        <xsl:value-of select="."/>
        </xsl:for-each>
        </xsl:template>
        </xsl:stylesheet>

        I hope that helps.

        V Offline
        V Offline
        VizOne
        wrote on last edited by
        #3

        Yes, it works great, thanks a lot! Regards, Andre Loker

        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