Re: [xsl] looking for an attribute

Subject: Re: [xsl] looking for an attribute
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Thu, 14 Sep 2006 13:36:27 +0200
Hi Aaron,

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

>>>> Example of root node, root node is "above" the root node of your xml doc.
<xsl:template match="/">
<xsl:if test="navigation/focusedTab[@name = 'Login']" >
....
</xsl:if>
</xsl:template>



>>>> Example of named template. Here the context node is still the root node:
<xsl:template match="/">
<xsl:call-template name="scripts" />
</xsl:template>
<xsl:template name="scripts">
<xsl:if test="navigation/focusedTab[@name = 'Login']" >
....
</xsl:if>
</xsl:template>


>>>> Example of normal template. Here the context node is "navigation":
<xsl:template match="/">
      <xsl:apply-template select="navigation"/>
</xsl:template>
<xsl:template match="navigation">
      <xsl:if test="focusedTab[@name = 'Login']" >
         ....
      </xsl:if>
</xsl:template>

In short: once you know "where you are" in the document parse tree, or in other words: are aware of the context node, you can find how your XPath expression should be like.

Good luck!

Cheers,
Abel Braaksma
http://abelleba.metacarpus.com



Aaron Johnson wrote:
Appologies if this is a repeated request...

I have some xml...

<navigation>
<focusedTab unremovable="true" immutable="true" ID="50" name="Login"/>
<inactiveTab unremovable="true" immutable="true" ID="38" name="Home"/>
</navigation>


I would like to test if the focused tab has an attribute of "login" so
as to impliment a choose statement...

<xsl:template name="scripts">
    <xsl:choose>
        <xsl:when test="?????'"> etc etc....

I thought it would be <xsl:when test="focusedTab[@name='Login']"> but
it won't work.

Any help would be appreciated.

Aaron

Current Thread