Re: [xsl] looking for an attribute

Subject: Re: [xsl] looking for an attribute
From: Abel Braaksma <>
Date: Thu, 14 Sep 2006 13:47:53 +0200
Abel Braaksma wrote:
Hi Aaron,

You'll need to add (and know) what the context node is. Suppose the following (expecting "navigation" to be your root node):

In addition, I'd like to add, that if you have multiple elements on the same axis with the name "focusedTab", than the statement will return true whenever *any* of these elements holds an attribute @name with the value "Login". To prevent that (not sure if this is a requirement), and to only process the nodes with the given requirement, it is almost always best to do the selection with "apply-template", instead of using an all-encompassing xsl:choose statement in a named or unnamed template. An example will clarify:

<xsl:template match="/">
<xsl:apply-templates select="navigation/focusedTab[@name = 'Login']" />
<xsl:template match="focusedTab">
... do whatever you would do inside the if-statement ...
... in case of multiple focusedTab elements, this would only be processing
your nodes with @name = 'Login', which was not the case in your if-
statement ...

This will effectively remove unwanted xsl:choose or xsl:if statement. Of course, it is not always possible to do it this way, otherwise we wouldn't be needing the xsl:if and xsl:choose. People from a procedural or OO language background often tend to think in terms of branching, using if-statements and the like, but XSLT is more like a predicate or declarative language, were you can let the thinking be done by the processor, instead of yourself.

Abel Braaksma

Current Thread