RE: [xsl] Cascading Attributes?

Subject: RE: [xsl] Cascading Attributes?
From: William Bagby <williamb@xxxxxxxxx>
Date: Wed, 30 May 2001 11:30:04 -0400
> You seem to be confusing <xsl:param> with <xsl:variable>
> ...
> There are some other problems with what you're trying as well, but if
> you consult a reference and clarify that distinction first (as well as
> looking into how to call a named template) you'll be on your way

>From <xsl:param>, p.263 of "XSLT Programmer's Reference" by Michael Kay:
"The only difference between parameters and variables is the way they
acquire an initial value."

This is why I used <xsl:param> rather than <xsl:variable>.  I wanted to be
able to use values passed to the template with <xsl:with-param>.  The
mistake I made was that I didn't have a 'select' attribute in
<xsl:with-param>, so the value wasn't being passed.  I added it, and it
works fine now.

> Michael
> -------------------------------------------------
> Michael Beddow
> http://www.mbeddow.net/

William Bagby.

----- Original Message -----
From: "William Bagby" <williamb@xxxxxxxxx>
To: "XSL Mailing List (E-mail)" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, May 25, 2001 4:50 PM
Subject: [xsl] Cascading Attributes?


> I have an XML element <text> with an optional attribute @class.  In
the
> template matching this element, I'd like to have a variable $class
which
> takes one of the following values, with lower number taking
precedence:
>
> 1. a param called class passed to the template using <with-param>
> 2. optional attribute @class if it is defined
> 3. the string "none"
>
> In other words, if my XSL is:
>
> <xsl:apply-templates select="text"/>
>
> I want $class to be text/@class if it is defined, otherwise "none".
But if
> my XSL is:
>
> <xsl:variable name="myvar">myclass</xsl:variable>
> <xsl:apply-templates select="text">
> <xsl:with-param name="myvar"/>
> </xsl:apply-templates>
>
> I want $class to be "myclass", regardless of whether or not @class is
> defined.
>
> I tried the following:
>
> <xsl:template match="text">
> <xsl:param name="class">
> <xsl:choose>
> <xsl:when test="@class"><xsl:value-of
> select="@class"/></xsl:when>
> <xsl:otherwise>none</xsl:otherwise>
> </xsl:choose>
> </xsl:param>
> <a href="{@href}" class="{$class}"><xsl:value-of select="."/></a>
> </xsl:template>
>
> But it doesn't work.  I'm sure I could probably figure it out, but I'm
> looking for something elegant, or at least something easy to read.
Maybe
> what I really want to know is why my XSL doesn't work, which is really
> another way of asking, "How does <xsl:param> work?"
>
>
> William Bagby.
>
>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread