AW: [xsl] problem with Xpath in Variable filled by choose

Subject: AW: [xsl] problem with Xpath in Variable filled by choose
From: "Dietmar Klotz" <dklotz@xxxxxxxxxxx>
Date: Wed, 16 Nov 2005 18:51:32 +0100
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@xxxxxxxxx]
Gesendet: Mittwoch, 16. November 2005 17:48
An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
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
________________________________________________________________________

Current Thread