[Home] [By Thread] [By Date] [Recent Entries]
Abel Braaksma wrote:
Hi Aaron,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> <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 ... </xsl:template> 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. Cheers, Abel Braaksma http://abelleba.metacarpus.com
|

Cart



