xsl-list
[Top] [All Lists]

RE: xsl 2.0 recursive functions and return value

2006-02-26 12:44:33
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/



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>