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

Re: Use of data() function (was: Re: [OT])

Subject: Re: Use of data() function (was: Re: [OT])
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Fri, 29 Feb 2008 16:15:45 +0000
Re:  Use of data() function (was: Re:  [OT])
On 29/02/2008, Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:
>  What exactly is meant by "effective boolean value" ?

Hi Mukul,

It's described here:

http://www.w3.org/TR/xpath20/#dt-ebv

>  How should this be exactly interpreted:
>  <xsl:if test="data(@married)">

I think test="@married" is the same as test="exists(@married)" whereas
data(@married) returns the typed value of @married and converts that
to true/false.

Here's a transform to demonstrate:

<xsl:stylesheet
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

    <!-- The schema is written directly within xsl:import-schema -->
    <xsl:import-schema>
        <xs:schema>
            <xs:element name="person" type="person"/>

            <xs:complexType name="person">
                <xs:simpleContent>
                    <xs:extension base="xs:string">
                        <xs:attribute name="married" type="xs:boolean"/>
                    </xs:extension>
                </xs:simpleContent>
            </xs:complexType>
        </xs:schema>
    </xsl:import-schema>

    <xsl:variable name="input">
        <person xsl:type="person" married="false">typed singleton</person>
        <person married="false">singleton</person>
    </xsl:variable>

    <xsl:template match="/" name="main">
        <xsl:for-each select="$input/person">
            <xsl:value-of select="concat('&#xa;',.)"/>
            <xsl:if test="data(@married)"> - married</xsl:if>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

the output is:

typed singleton
singleton - married

As you can see "married" is output even though it's value if false.

I'm not sure this is a great example - if it can be made more real
world let me know and I'll add it to http://schema-aware.com

-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

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.