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

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

Hi Mukul,

It's described here:

>  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:

    xmlns:xsl=""; version="2.0">

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

            <xs:complexType name="person">
                    <xs:extension base="xs:string">
                        <xs:attribute name="married" type="xs:boolean"/>

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

    <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>


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

Andrew Welch

Current Thread