Hi, Raymond.

Raymond <[EMAIL PROTECTED]> wrote on 2007-08-10 12:55:19 PM:
> I'm wondering if there is anyway to achieve something like this:
> 
> <xsl:variable name="category_defs">
>    <xsl:for-each select="$category_defs1" >
>       <xsl:copy>
>          <xsl:attribute name="mode">1</xsl:attribute>
>       </xsl:copy>
>    </xsl:for-each>
>    <xsl:for-each select="$category_defs2" >
>       <xsl:copy>
>          <xsl:attribute name="mode">2</xsl:attribute>
>       </xsl:copy>
>    </xsl:for-each>
> </xsl:variable>
> 

> Essentially, what I'm trying to do is merge the two result sets into
> one interleaved set, while maintaining the distinction between the 
> two by applying a "mode" attribute.

According to section 11.1 of XSLT 1.0,[1] "An operation is permitted on a 
result tree fragment only if that operation would be permitted on a string 
(the operation on the string may involve first converting the string to a 
number or boolean)."  So in standard XSLT, you can't do it.  To be able to 
access the nodes in a result tree fragment and directly manipulate them, 
you need to use the node-set extension function.  Something like the 
following should work:

<xsl:variable name="category_defs"
        xmlns:exslt="http://exslt.org/common";>
   <xsl:for-each select="exslt:node-set($category_defs1)/node()" >
      <xsl:copy>
         <xsl:attribute name="mode">1</xsl:attribute>
      </xsl:copy>
   </xsl:for-each>
   <xsl:for-each select="exslt:node-set($category_defs2)/node()" >
      <xsl:copy>
         <xsl:attribute name="mode">2</xsl:attribute>
      </xsl:copy>
   </xsl:for-each>
</xsl:variable>

I hope that helps.

Thanks,

Henry
[1] http://www.w3.org/TR/xslt#section-Result-Tree-Fragments
------------------------------------------------------------------
Henry Zongaro      XSLT Processors Development
IBM SWS Toronto Lab   T/L 969-6044;  Phone +1 905 413-6044
mailto:[EMAIL PROTECTED]

Reply via email to