[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
> 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/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|