RE: [xsl] copying variables and bits of XML databases for XSL processing

Subject: RE: [xsl] copying variables and bits of XML databases for XSL processing
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Thu, 19 Apr 2001 11:34:12 +0100
>
> One of my stylesheets need to copy one the $dbWNc and $dbWNj
> variables in
> another variable according to which section we're in. Here's
> the code I
> wanted to use:
>
>   <xsl:variable name="current_db">
>     <xsl:if test="$collection = 'collection'"><xsl:copy-of
> select="$dbWNc"/></xsl:if>
>     <xsl:if test="$collection = 'jeans'"><xsl:copy-of
> select="$dbWNj"/></xsl:if>
>   </xsl:variable>
>
> where $collection held the "section" information. This
> doesn't work since
> when I try to access my new variable like this for example, I get an
> "Unspecified error" from MSXML 3.0sp1:
>
> <xsl:variable name="items" select="count($current_db//item)"/>
>
$current_db is a result tree fragment, and you can't use an RTF in a path
expression. One solution is to convert it to a node-set using the
xx:node-set() extension function. Better is to make the variable a node-set
in the first place:

<xsl:variable name="current_db"
  select="$dbWNc[$collection='collection'] |
          $dbWNj[$collection='jeans']"/>

This has the advantage that it avoids the unnecessary and potentially
expensive <xsl:copy-of> .

Mike Kay
Software AG


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread