This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

using default params?



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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]