[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Matching braches without a certain node

Subject: Re: Matching braches without a certain node
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 29 Nov 2000 01:42:38 -0800 (PST)
braches
Hi Ted,


>   <xsl:for-each select="//middle">
>     <xsl:if test="not (foo[node()]">
>       [Whatever I want to do]
>     </xsl:if>
>   </xsl:for-each>


The expression not (foo[node()] has unbalanced brackets and will
generate an error from the XSLT processor.

More importantly, after you add the missing closing ')', this will not
eliminate all "nodes that _don't_ have the 'foo' node" .

It will return a node-set of all child elements that do not have a
'foo' child with a node child.

So, in case you add another 'middle' element (id=4) at the end of your
xml document, like the following:

<top>
  <middle id="1">
      <data>value</data>
      <foo>bar</foo>
  </middle>
  <middle id="2">
      <data>value</data>
  </middle>
  <middle id="3">
      <data>value</data>
      <foo>bar</foo>
  </middle>
  <middle id="4">
      <data>value</data>
      <foo/>
  </middle>
</top>


Then the expression //middle[not (foo[node()])]

returns a nodeset of two elements:

  <middle id="2">
      <data>value</data>
  </middle>

and  


  <middle id="4">
      <data>value</data>
      <foo/>
  </middle>

As you can see, the second node in the returned node-set still has a
'foo' child.

The expression that will return all 'middle' elements that do not have
a 'foo' child is:

//middle[not(foo)]


Dimitre Novatchev.



Theodore Weatherly wrote:

Suppose we have this XML:

<top>
  <middle id="1">
      <data>value</data>
      <foo>bar</foo>
  </middle>
  <middle id="2">
      <data>value</data>
  </middle>
  <middle id="3">
      <data>value</data>
      <foo>bar</foo>
  </middle>
</top>

I want to match the 'middle' nodes that _don't_ have the 'foo' node
(id==2).
This seems to work:

<xsl:template match="/">
  [stuff before]
  <xsl:for-each select="//middle">
    <xsl:if test="not (foo[node()]">
      [Whatever I want to do]
    </xsl:if>
  </xsl:for-each>
</xsl:template>

(You get the general idea.) Isn't there any simpler way to do this?? 
I'd
rather do something where, in one line, I match the 'middle' nodes
without
the 'foo' tag, and then do an unconditional loop over these nodes.

Thanks!

-Ted



__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.