RE: testing for null string in a node

Subject: RE: testing for null string in a node
From: "Christof Schneider" <Christof_Schneider@xxxxxx>
Date: Mon, 6 Nov 2000 23:21:00 +0100
You can use the string()-function to accomplish the task.

xsl:when test="string(.)">
 ...do something...
</xsl:when>

This relies on implicit type conversion. test="" expects a boolean value,
string() delivers a string-value. Conversion rule for string to boolean
says: a zero-length string converts to false, everything else to true.  The
string function tries to convert the argument to a string. For a node-set it
is the value of the text node, for a result tree fragement (what you often
get from using a variable) the result is the sequence (concatenation) of all
(self and descendant) text nodes. Beware of white spaces.

Have a look at Michael Kay's book [page 427, 508-509]

Instead of the current node you can use a variable, or name any other
node(s).

Hope it helps,

- Christof


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxx]On Behalf Of
> mxmodi@xxxxxxxxxxxxxxx
> Sent: Montag, 6. November 2000 19:43
> To: xsl-list@xxxxxxxxxxxxxxxx
> Subject: testing for null string in a node
>
>
>
> Hi,
>
> I want to be able to test if the value of a certain node is empty and
> depending on the result, perform more functions. I am having some troublwe
> understanding how to test for that. Any help is appreciated.
>
> Here is the sample XML:
>
>
> <root>
> <Names>
>   <Name>
>     <FN>aaa</FN>
>     <LN>bbb</LN>
>     <Dates>
>       <Date>
>         <Begin>11/11</Begin>
>         <End>12/11</End>
>            <Projects>
>               <Project>
>      <Name>proj a</Name>
>      <Code>abc-123</Code>
>               </Project>
>            ........More <Project> Nodes
>            </Projects>
>       </Date>
>        .....more <Date> Nodes
>     </Dates>
>   </Name>
>     ...........more <Name> Nodes
> </Names>
> </root>
>
>
> Here is the sample XSL:
>
> <xsl:template match="/">
> ...perform some code...
> <xsl:apply-templates select="//Names/Name" >
> <xsl:sort select="FN" />
> </xsl:apply-templates>
> </xsl:template>
>
> <xsl: template match="Name">
> <xsl:choose>
> <xsl:when test="*[not(child::FN)]">
> ...do something...
> </xsl:when>
> <xsl:otherwise>
> ...do something else...
> </xsl:otherwise>
> </xsl:choose>
>
> ...continue doing rest of the stuff..
> </xsl:template>
>
>
>
>  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