[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

using default params?

Subject: using default params?
From: Jens Lautenbacher <jtl@xxxxxxxxxx>
Date: 28 Mar 2000 20:09:28 +0200
xsl default param
Hi,

I have the following problem:

I want to render some xml tag <foo> into some complicated html code,
let's just assume for this example that it will be 3 tables with 3
different bgcolors.

so my xsl sheet produces from <foo>bar</foo>

<table bgcolor="#ff0000"><tr><td>bar</td></tr><table>
<table bgcolor="#00ff00"><tr><td>Second</td></tr><table>
<table bgcolor="#0000ff"><tr><td>Third</td></tr><table>

Now I want to be able to override the color in the 3 table via
attributes to foo.

So this becomes:

<foo col1="#ff0000" col2="#00ff00" col3="#0000ff">bar</foo>

and the xsl

<xsl:template match="foo">
   <table bgcolor="{@col1}"><tr><td><xsl:apply-templates/></td></tr><table>
   <table bgcolor="{@col2}"><tr><td>Second</td></tr><table>
   <table bgcolor="{@col3}"><tr><td>Third</td></tr><table>
</xsl:template>

But I don't want to always give the full set of attributes, but
instead have my xsl respect default values.

I don't want to use the DTD for supplying the defaults, because then
it would be cluttered with stuff that is only design and no structural
information.

Of course supplying the col? attributes itself in the xml file goes
beyond structural description, but for reasons beyond this little
example it makes sense in my case...

So I tried to do some stupid and nonworking tricks with xsl:call-template:

<xsl:template match="foo">
 <xsl:call-template name="foo_pr">
   <xsl:with-param name="col1" select="@col1"/>
   <xsl:with-param name="col2" select="@col2"/>
   <xsl:with-param name="col3" select="@col3"/>
 </xsl:call-template>
</xsl:template>

<xsl:template name="foo_pr">
   <xsl:param name="col">#ff0000</xsl:param>
   <xsl:param name="col">#00ff00</xsl:param>
   <xsl:param name="col">#0000ff</xsl:param>
   <table bgcolor="{$col1}"><tr><td><xsl:apply-templates/></td></tr><table>
   <table bgcolor="{$col2}"><tr><td>Second</td></tr><table>
   <table bgcolor="{$col3}"><tr><td>Third</td></tr><table>
</xsl:template>

until I realized that <xsl:with-param> will also supply a (then empty)
parameter when @col? is empty... which will overwrite the default
param in the named template.

Is there any way that I can set a param to a value which will be given
back from an evaluated expression? 

What I'm looking for is something like being able to 

<xsl:param name="a_name" select="eval(@a_name or 'default_value')"/>

where the result of the eval is the value of @a_name if not '' and
'default_value' otherwise.


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.