Re: newbie xsl:if

Subject: Re: newbie xsl:if
From: "Alistair MacDonald" <AlistairMacDonald@xxxxxxxxxxxxx>
Date: Wed, 09 Jun 1999 11:24:08 +0100
I asked a similar question a long time ago (and repeated it when the latest draft came out). I didn't get an aswer then, but was playing with it yesterday and worked out a (trivial) solution. You need to be using something which conforms to the latest draft (or supports variables properly). It is also possible to do something non-standard using the MS processor.

XML Fragment:

<area name="foo">
  <page name="index">
  <page name="foo">

XSL Fragment:

<xsl-template match="page">

<!-- ** The trick is to set a variable, because you can control the context of the variable when you set it -->
<!-- extract the parents "name" -->
<xsl:variable name="parent" expr="from-parent(node())/from-attributes(name)" />

<!-- Now you can compare the current name with the variable. It doesn't matter what context you use because the variable is now set -->
<xsl:if test="from-attributes(name)=$parent">
Found element .....


Hope this helps. It certainly should work in the latest version of XT, although I might have made an error when I translated it!


PS I deliberately used the unified (aka long) syntax to make it clear that it worked only with the new version

>>> James Kerr <james@xxxxxxxxxxxx> 06/07 9:22 pm >>>

I am trying to learn XSL and have a question:
How would I form a match statement for an xsl:if that would match a
parent's value with the value of the current element?  In other words, I
have a list of sub-elements and want to determine which element has the
same value as the parent.



 XSL-List info and archive:

Current Thread
  • newbie xsl:if
    • James Kerr - Mon, 07 Jun 1999 16:22:57 -0400
      • <Possible follow-ups>
      • Alistair MacDonald - Wed, 09 Jun 1999 11:24:08 +0100 <=