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

RE: Testing for presence of node

Subject: RE: Testing for presence of node
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 21 Jun 2002 21:20:09 +0100
xsl presence of node
> 
> For each category element if you want to check for 
> subcategory as its children, you can do :
> 
> <xsl:for-each select="//category">
> 
>         <xsl:if test="string-length(./*[name()=subcategory]) >0 )
>            Success
>         </xsl:if> 
> 
>         <xsl:if test="string-length(./*[name()=subcategory])=0 )
>            Failure
>         </xsl:if> 
> 
> </xsl:for-each>

1. ./x is a long-winded way of writing x
2. You meant name()='subcategory' with quotes
3. ./*[name()='subcategory'] is a long-winded way of writing
./subcategory
4. The guy wants to know if the subcategory element exists, not if it
has non-empty text content.
5. Why test the same condition twice, rather than using xsl:choose?

Try instead:

<xsl:choose>
<xsl:when test="subcategory">Success</xsl:when>
<xsl:otherwise>Failure</xsl:when>
</xsl:choose>

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> 
> > 
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> > 
> > I have an XML file that contains the following structure:
> > 
> > <category>
> >   <subcategory>
> >     <article>
> >     </article>
> >   </subcategory>
> > </category>
> > 
> > In my XSLT stylesheet, I need to be able to test if the <category> 
> > node I'm working with contains a <subcategory> node. What's 
> the best 
> > way to test for the presence of this node without actually doing 
> > anything with it? I was thinking <xsl:if test="something">.
> > 
> > - -joeljkp
> > 
> > - ---------------------------------------
> > http://www.ballsome.com
> > 
> > -----BEGIN PGP SIGNATURE-----
> > Version: PGPfreeware 7.0.3 for non-commercial use 
<http://www.pgp.com>
> 
> iQA/AwUBPRKA7H880CLOJa2eEQJxpwCg6XhYuz/DsUThGatqbkDa99G85XAAoL8b
> GrkEiFZTOBoCy9EHV1HxOiTA
> =ASvZ
> -----END PGP SIGNATURE-----
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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


 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.