xsl-list
[Top] [All Lists]

AW: problem with Xpath in Variable filled by choose

2005-11-16 10:51:32
I am not sure if i understand the concept fully. If I follow your advice my
output of: <xsl:copy-of select="$CategoryPointer"/>

Is than this:
                <news xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
                    <HeadlineColor>#ff0000</HeadlineColor>
                    <TeaserColor>#00ff00</TeaserColor>
                    <TeaserColorSub>#0000ff</TeaserColorSub>
                </news> 

But if I do: 
<xsl:copy-of select="$CategoryPointer/HeadlineColor"/>

I don't get anything but I want to have this output:
#ff0000

Thanks for your answer also I didn't understand fully it helped already :)

Didi

-----Ursprüngliche Nachricht-----
Von: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk] 
Gesendet: Mittwoch, 16. November 2005 17:48
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff: Re: [xsl] problem with Xpath in Variable filled by choose



  <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/*[na
me()=$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>
--~--



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