xsl-list
[Top] [All Lists]

Re: Getting value of specific element in external XML document

2004-04-22 16:25:38
Hi Wendell,

Thank you for you very quick answer, but....

In the example, my input xml would look like (something):

<?xml version="1.0"?>
<node a="hello">
 <node a="Hi">
   <node a="Godday"></node>
   <node a="Godday"></node>
   <node a="Godday"></node>
 </node>
</node>

Here, in the example I had, I would like the colours to be
Red, Green, Bluez respectively for Hello, Hi and Godday (Bluez should of course be Blue..)

I forgot that there exists a node() with a distinct meaning. In my real xml, the name is 'Menu', and you should interchange all where I wrote 'node' to 'Menu'. The problem still persists.

I have tried, successfully:
<xsl:comment><xsl:value-of select="count(ancestor-or-self::Menu)"/></xsl:comment> (or node) which gives a comment telling me where it is. When I do the same inside the predicate, then it goes wrong.

I have a working solution:
<xsl:variable name="n"><xsl:value-of select="count(ancestor-or-self::Menu)"/></xsl:variable>
<xsl:variable name="c">
 <xsl:choose>
   <xsl:when test="$n=1"><xsl:value-of select="$Colours[1]"/></xsl:when>
   <xsl:when test="$n=2"><xsl:value-of select="$Colours[2]"/></xsl:when>
   <xsl:when test="$n=3"><xsl:value-of select="$Colours[3]"/></xsl:when>
   <xsl:when test="$n=4"><xsl:value-of select="$Colours[4]"/></xsl:when>
   <xsl:when test="$n=5"><xsl:value-of select="$Colours[5]"/></xsl:when>
   <xsl:when test="$n=6"><xsl:value-of select="$Colours[6]"/></xsl:when>
   <xsl:otherwise><xsl:value-of select="$Colours[7]"/></xsl:otherwise>
 </xsl:choose>
</xsl:variable>

Which I have implemented at the moment, but I would still very much like to know what is wrong with the other one...

If you say that it should work, given the names of the elements being correct, then...
Or have I misunderstood your reply?

Regards,
Ragulf Pickaxe :-)


From: Wendell Piez <wapiez(_at_)mulberrytech(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Getting value of specific element in external XML document
Date: Thu, 22 Apr 2004 19:02:43 -0400

Sir Pickaxe,

What you want is not

  ancestor-or-self::node

but rather

  ancestor-or-self::node()

You are presently asking for element nodes named node. Apparently you have none of those. An easy error, but hard to catch.

Cheers,
Wendell

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail