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

RE: xsl 2.0 recursive functions and return value

Subject: RE: xsl 2.0 recursive functions and return value
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 26 Feb 2006 19:44:33 -0000
xsl return value
> how can i get the following to work:
> 
> 
> <xsl:function name="r2c:hasTextContent" as="xs:boolean">
>    <xsl:param name="node"/>
>      <xsl:for-each select="$node/*">
>        <xsl:choose>
>          <!--ignore!-->
>          <xsl:when test="r2c:isOutputNode(.)"/>
>          <!--gotcha!-->
>          <xsl:when test="r2c:isLeafNode(.)">
>            <xsl:value-of select="true()"/>
>          </xsl:when>

Use xsl:sequence here! xsl:value-of creates a text node. You're converting a
boolean to a string, wrapping the string in a text node, then because an
xs:boolean is required, the text node is atomized, and the string "true" is
converted back to a boolean.

>          <xsl:otherwise>
> 	<!-- recurse into the current node -->
>            <xsl:sequence select="r2c:hasTextContent(.)"/>
>          </xsl:otherwise>
>        </xsl:choose>
>      </xsl:for-each>
>    <!-- no leafNodes found?:-->
>    <xsl:sequence select="false()"/>
> </xsl:function>
> 
> this will inevitably put more than one boolean into my output 
> sequence, 
> which will cause an error.

Only if there is more than one leaf node.

> Any hints?

Try:

<xsl:function name="r2c:hasTextContent()" as="xs:boolean">
  <xsl:param name="node" as="node()"/>
  <xsl:sequence select="some $x in $node/*[not(r2c:isOutputNode(.)]
satisfies
     (r2c.isLeafNode($x) or r2c.hasTextContent($x))"/>
</xsl:function>

Michael Kay
http://www.saxonica.com/

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.