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

Re: How do I check to see if any of my descendants co

Subject: Re: How do I check to see if any of my descendants contain a certain value?
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Fri, 03 Aug 2007 15:24:23 +0200
Re:  How do I check to see if any of my descendants  co
Richard Sayre wrote:
I am trying to check me XML to see if any of the descendants contain a
certian value.

<snip />

I can have unlimited Child Types in each type.  When I get to a
certain type, I want to check and see if this node or any descendants
of this node has a value of 0 for the inUse node.

This is what I tried but it did not work:

<xsl:if test="descendant-or-self::inUse = 0">

Change it to the following and you should be fine (you are looking for string, not for a number):
<xsl:if test="descendant-or-self::inUse = '0'" >


Depending on what you are after, you may want to remove the xsl:if and change it to something like this with apply-templates on the place of your xsl:if:

<xsl:template match="node-to-test[descendant-or-self::inUse = '0' ]">
  ...
</

which will leave the thinking about order and logic to the processor. Also, you can change descendant-or-self:: to .// (yes, the dot is supposed to be there, otherwise the search will be done from the root).

That brings me to another thing. If you all you need is a stylesheet that outputs something when a certain child has a certain value, you may as well do this instead:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="inUse[.='0']">FOUND<xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>


The last match is to disable the default stylesheet for text nodes, the first one matches when your criterion is met. In XSLT 2.0 you can put this criterion in a parameter and then you have effectively created an XML search tool (by setting the parameter on the commandline) ;)

Cheers,
-- Abel Braaksma

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.