RE: [xsl] xsl:for-each result

Subject: RE: [xsl] xsl:for-each result
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 4 Mar 2005 17:49:39 -0000
> I'm binding the result of for-each to a variable like this:
>     <xsl:variable name="title-suffix">
>       <xsl:for-each select="relation_list/relation[@class='REP']">
>         <xsl:call-template name="title-suffix">
>           <xsl:with-param name="relation" select="."/>
>         </xsl:call-template>
>       </xsl:for-each>
>     </xsl:variable>
> My problem arises when no nodes match the select expression and so the
> title-suffix template isn't called.  Shouldn't the 
> title-suffix variable
> be bound to an empty sequence, whose effective boolean value is false?

No, it's bound to an empty tree: a document node with no children, whose
effective boolean value is true.

You're using 2.0 here. In 2.0 this kind of thing is done much more easily
using functions. Something like:

<xsl:variable name="title-suffix"
  select="for $x in relation_list/relation[@class='REP']
          return title-suffix($x)"/>

Michael Kay

Current Thread