|
Subject: Help with xsl:constant and Are There Xsl Variables? From: "Douglas Nehring" <dnehring@xxxxxxxxxxxxxxxxxx> Date: Mon, 19 Apr 1999 10:40:18 -0400 |
A little knowledge is starting to prove dangerous. Thanks for the help with
conditionals, but I think it has just wetted by appetite. As previous
viewers may recall, I was trying to color code entries based on a type
attribute. However what I found myself doing was repeating a lot of "code".
Here's a snippet of what I was doing in the xsl:
<xsl:template match='entry[@type="type1"]/author'>
<tr>
<td WIDTH="15%">
<DIV STYLE="background-color:black; color:white; height:100%; width:100%;">
<SPAN STYLE="font-weight:bold; color:white"></SPAN>
Author:
</DIV>
</td>
<td>
<DIV STYLE="background-color:blue; color:white; width:100%;">
<SPAN STYLE="font-weight:bold; color:white"></SPAN>
<xsl:apply-templates/>
</DIV>
</td>
</tr>
</xsl:template>
And I had to repeat this for each child element of entry and for each entry
type (i.e. for "type2" I had an exact copy of the above but with a color
specified as red-everything else was the same.) I would like to reduce
redundant code and I see that I could specify the color as an attribute of
entry (and thereby just grab the color), but I really want to keep the
presentation separate from the content. I took a look as the XSL spec and I
see that there are global constants <xsl:constant name="type1"
value="blue"/> , but doing something <DIV
style="background-color:{constant(../@type)} ... doesn't work for me (I'm
using XT). Doing it this way would allow me to create a crude Hashtable to
store the type/color pairs and then lookup the color based on the entry type
attribute. Can I lookup a constant the way I am trying or do you have to
explicitly specify the constant (i.e. {constant(type1)} ).
Another idea, ok question, I got after seeing the xsl:constant was "is there
an "xsl:variable" or equivalent"? What I could do if there was (at least
what I would try to do) is assign the color for the entry type to the
variable and then have the <DIV style... use that variable(s) to assign
colors. Something sort of like:
<!-somehow assign the color to a "xsl variable" based on the entry type not
sure how to do that yet-->
TBD
<!-now use the variable to assign the color -->
<DIV STYLE="background-color:'xsl:variable value';...
I hope what I trying to convey here is clear.
Regards,
Doug Nehring
Here's the base xml and xsl I'm playing with if it's of any help.
<body>
<entry type="type1">
<title>title</title>
<author>author</author>
<desc>text</desc>
<entry>
<entry type="type2">
<title>title2</title>
<author>author2</author>
<desc>text2</desc>
<entry>
<entry type="type3">
<title>title3</title>
<author>author3</author>
<desc>text3</desc>
<entry>
</body>
<portions of xsl>
<xsl:template match="entry">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" WIDTH="82%">
<xsl:apply-templates/>
<BR/>
</TABLE>
</xsl:template>
<xsl:template match="title">
<tr>
<td WIDTH="15%">
<DIV STYLE="background-color:black; color:white; height:100%; width:100%;">
<SPAN STYLE="font-weight:bold; color:white"></SPAN>
Title:
</DIV>
</td>
<td>
<!-the background-color is what will be changing based on the entry type -->
<DIV STYLE="background-color:blue; color:white; width:100%;">
<SPAN STYLE="font-weight:bold; color:white"></SPAN>
<xsl:apply-templates/>
</DIV>
</td>
</tr>
</xsl:template>
<xsl:template match="author">
<tr>
<td WIDTH="15%">
<DIV STYLE="background-color:black; color:white; height:100%; width:100%;">
<SPAN STYLE="font-weight:bold; color:white"></SPAN>
Author:
</DIV>
</td>
<td>
<DIV STYLE="background-color:blue; color:white; width:100%;">
<SPAN STYLE="font-weight:bold; color:white"></SPAN>
<xsl:apply-templates/>
</DIV>
</td>
</tr>
</xsl:template>
<xsl:template match="desc">
<tr>
<td WIDTH="15%">
<DIV STYLE="background-color:black; color:white; height:100%; width:100%;">
<SPAN STYLE="font-weight:bold; color:white"></SPAN>
Reference:
</DIV>
</td>
<td>
<DIV STYLE="background-color:blue; color:white; width:100%;">
<SPAN STYLE="font-weight:bold; color:white"></SPAN>
<xsl:apply-templates/>
</DIV>
</td>
</tr>
</xsl:template>
</portions of xsl
Doug Nehring
Nortel Networks
MSL-100 Advanced Technology
Richardson, TX
(972) 685-2096, ESN 445-2096
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: Whither FOP?, James Tauber | Thread | RE: Help with xsl:constant and Are , Kay Michael |
| Whither FOP?, Michael . Reinertsen | Date | RE: Problem instantiating XMLDOMDoc, Jonathan Borden |
| Month |