xsl-list
[Top] [All Lists]

Re: [xsl] Checking a parent's attribute

2007-02-07 02:07:15
On 07/02/2007, at 4:07 PM, G. Ken Holman wrote:

<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.

That was exactly what I was after, I didn't realise I could do that. Thanks for your help Ken.

Cheers,
Nick

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>