Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 6th, 2007, 07:11 PM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checking boolean attribute in XSLT

I have the following xml.

Note: 'good' attribute is a boolean.

<Kidroom>
      <Toy>
         <Condition good="true">
             <Color>Blue</Color>
             <Item>Kite</Item>
         </Condition>
        <Condition good="false">
             <Color>White</Color>
             <Item>Ball</Item>
         </Condition>
      </Toy>
</Kidroom>


I like to display all toys if their good conditions are 'true' (boolean).

My XSLT so far:

<xsl:template match=Kidroom">
   <xs:apply-templates select="Toy"/>
</xsl:template>

<xsl:template match=Toy">
   <xs:apply-templates select="Condition"/>
</xsl:template>

<xsl:template match="Condition[@good='true']">
   <xsl:copy-of select="."/>
</xsl:template>

I think the problem is at the last template. It seem to be checking 'true' as a string, instead of a boolean. Also, am I calling the the last template correctly using
<xs:apply-templates select="Condition"/> ?


Appreciate any helps.


 
Old February 6th, 2007, 08:22 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you are using schema-aware processing in XSLT 2.0, then the predicate should be

Condition[@good=true()]

Otherwise, the string match looks fine.

The apply-templates looks fine too.

What symptoms are you suffering from?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in XSLT with "//" in attribute value kaps77 XSLT 3 November 6th, 2007 10:57 AM
XSLT, add attribute ik XSLT 6 August 22nd, 2006 11:03 AM
xslt for each and attribute tag desse XSLT 1 May 24th, 2006 08:01 AM
changing attribute value in xslt rameshnarayan XSLT 1 August 16th, 2005 08:07 AM
Add attribute to the parent after checking child kinnur XSLT 10 May 30th, 2005 06:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.