xsl-list
[Top] [All Lists]

Re: problem with Xpath in Variable filled by choose

2005-11-16 09:48:08


  <xsl:variable name="CategoryPointer"> 
                 <xsl:choose> 
                      <xsl:when test="$category = 'main'"> 
                           <xsl:copy-of 
  select="document('style.xml')/root/DeviceParameters/DesignMood/Category/main
  "/>           
                      </xsl:when> 

Note that's a relatively expensive way of setting things up as it imples
_copying_ the selected tree. 

If xsl:variiabel is used with no as= attribute it always generates a new
tree with a new document node (/)

In this case the child of / will be either a main element or a news
element depending on the test.

So this
            <xsl:value-of select="$CategoryPointer/HeadlineColor"/> 
will never select anything as the child of $CategoryPointer is never a
HeadlineColor element. It is either a main element (from the first
branch) or a text node (from the second branch)


I suspect you actually just want the variable to refererence in to nodes
in your input tree rather than to copies, so:


<xsl:variable name="CategoryPointer" as="element()"> 
                 <xsl:choose> 
                      <xsl:when test="$category = 'main'"> 
                           <xsl:sequence
select="document('style.xml')/root/DeviceParameters/DesignMood/Category/main
"/>           
                      </xsl:when> 
                      <xsl:when test="$category = 'news'"> 
                           <xsl:sequence
select="document('style.xml')/root/DeviceParameters/DesignMood/Category/news
"/>                
                      </xsl:when> 
                 </xsl:choose> 
            </xsl:variable> 


or equivalently the less verbose form:

<xsl:variable name="CategoryPointer" 
 
select="document('style.xml')/root/DeviceParameters/DesignMood/Category/*[name()=$category]"/>


David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
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>
--~--