Subject: RE: Getting value of specific element in external XML document
From: "Josh Canfield" <Josh.Canfield@xxxxxxxxxxxx>
Date: Thu, 22 Apr 2004 16:42:24 -0700
|
<xsl:value-of select="$Colours[count(ancestor-or-self::node)]"/>
I think that in the predicate the ancestor-or-self would be based from the variable $Colours, you want to count the ancestor nodes of current()? or store . in a variable to use.
<xsl:value-of select="$Colours[count(current()/ancestor-or-self::node)]"/>
Josh
-----Original Message-----
From: Ragulf Pickaxe [mailto:jawxml@xxxxxxxxxxx]
Sent: Thursday, April 22, 2004 3:39 PM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: Getting value of specific element in external XML
document
Hi all,
I have the following problem:
During a transformation, I want different Colours on some elemets according
to their position in the hierachy. Instead of a choose-when, I have tried
following:
<!-- Top of XSL document -->
<xsl:variable name="Colours"
select="document('Colours.xml')/colours/colour"/>
<xsl:template match="/">
<xsl:copy-of select="$Colours"/> <!-- Gives back the whole -->
<xsl:value-of select="$Colours[2]"/> <!-- Gives back the value of the
second colour element -->
<xsl:apply-templates select="node"/>
</xsl:template>
<xsl:template match="node">
<xsl:value-of select="$Colours[count(ancestor-or-self::node)]"/> <!--
Gives nothing at all -->
<xsl:apply-template select="node"/>
</xsl:template>
In the template node, I have tried various things in the predicate, such as
[position()=count(ansestor-or-self::node)] and the like, but nothing seems
to work, except when I hardcode the value, which I obviously do not want.
What am I doing wrong here? I have absolutely no idea why this is not
working.
The Colours.xml looks like the following:
<?xml version="1.0"?>
<colours>
<colour>red</colour>
<colour>green</colour>
<colour>bluez</colour>
</colours>
Regards,
Ragulf Pickaxe :-|
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
|