Re: [xsl] Checking a parent's attribute

Subject: Re: [xsl] Checking a parent's attribute
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 06 Feb 2007 21:07:53 -0800
At 2007-02-07 15:51 +1100, you wrote:
I've got some xslt that used to do the following :

<xsl:for-each select="ExportEntries/ExportEntry/Field">

but I realised I need it to be conditional on an attribute of one of
the parent nodes, so I ended up splitting it up into 3 lines instead :

<xsl:for-each select="ExportEntries">
        <xsl:if test="../Restore/@state = 'True'">
                <xsl:for-each select="ExportEntry/Field">

This works as I want, but to me it doesn't seem to be the best way.
Is there a better way to do that kind of check?  I want to restrict
it to the "ExportEntries" node first, as there are only a limited
number of times that that node will exist, and the "Restore state"
node is often there for other things, so I think I'm being more
efficient doing it this way.  Am I doing this right?

You use a predicate to achieve this:


  <xsl:for-each select="ExportEntries[../Restore/@state='True']/
                        ExportEntry/Field">
    ...
  </xsl:for-each>

I hope this helps.

. . . . . . . . . . Ken


-- World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread