Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Multiple Valued Variables in XSLT

Reply
Thread Tools

Multiple Valued Variables in XSLT

 
 
John Kooistra
Guest
Posts: n/a
 
      07-02-2004
Hi,

I'm trying to set the font colour and background colour in HTML based
on an XSL condition a la:

<xsl:variable name="font">
<xsl:choose>
<xsl:when test="SOME TEST">
<fontcolour>Red</fontcolour>
<bgcolour>Blue</bgcolour>
</xsl:when>
<xsltherwise>
<fontcolour>Black</fontcolour>
<bgcolour>White</bgcolour>
</xsltherwise>
</xsl:choose>
</xsl:variable>
<td bgcolor="{$font/bgcolour}">
<font color="{$font/fontcolour}">
TEXT
</font>
</td>

However, I get the error: "Reference to variable or parameter 'font'
must evaluate to a node list."

I get it because $font is a Result Tree Fragment.

Is there a way to get the functionality I want without using a
processor dependent function like msxsl:node-set(rtf)?

As a work-around, I'm currently using two separate variables for
fontcolour and bgcolour complete with their own condition statements.
Obviously, it is very ugly and I would really appreciate any
suggestions you have.

Thanks a million,
John
 
Reply With Quote
 
 
 
 
-
Guest
Posts: n/a
 
      07-02-2004
John Kooistra wrote:
> Hi,
>
> I'm trying to set the font colour and background colour in HTML based
> on an XSL condition a la:
>
> <xsl:variable name="font">
> <xsl:choose>
> <xsl:when test="SOME TEST">
> <fontcolour>Red</fontcolour>
> <bgcolour>Blue</bgcolour>
> </xsl:when>
> <xsltherwise>
> <fontcolour>Black</fontcolour>
> <bgcolour>White</bgcolour>
> </xsltherwise>
> </xsl:choose>
> </xsl:variable>
> <td bgcolor="{$font/bgcolour}">
> <font color="{$font/fontcolour}">
> TEXT
> </font>
> </td>
>
> However, I get the error: "Reference to variable or parameter 'font'
> must evaluate to a node list."
>
> I get it because $font is a Result Tree Fragment.
>
> Is there a way to get the functionality I want without using a
> processor dependent function like msxsl:node-set(rtf)?


I'm pretty sure there isn't, as that behaviour is designed into the XSLT
spec. Annoying in many respects, don't know if there are plans to change
the behaviour in XSLT 2.0?

Regards

Will
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      07-02-2004


John Kooistra wrote:


> I'm trying to set the font colour and background colour in HTML based
> on an XSL condition a la:
>
> <xsl:variable name="font">
> <xsl:choose>
> <xsl:when test="SOME TEST">
> <fontcolour>Red</fontcolour>
> <bgcolour>Blue</bgcolour>
> </xsl:when>
> <xsltherwise>
> <fontcolour>Black</fontcolour>
> <bgcolour>White</bgcolour>
> </xsltherwise>
> </xsl:choose>
> </xsl:variable>
> <td bgcolor="{$font/bgcolour}">
> <font color="{$font/fontcolour}">
> TEXT
> </font>
> </td>
>
> However, I get the error: "Reference to variable or parameter 'font'
> must evaluate to a node list."
>
> I get it because $font is a Result Tree Fragment.
>
> Is there a way to get the functionality I want without using a
> processor dependent function like msxsl:node-set(rtf)?
>
> As a work-around, I'm currently using two separate variables for
> fontcolour and bgcolour complete with their own condition statements.
> Obviously, it is very ugly and I would really appreciate any
> suggestions you have.


I don't know to what kind of user agents you want to send your HTML but
if you target current desktop browsers like IE5+, Netscape 6/7, Opera
6/7 then I wouldn't bother with bgcolor or that <font> element but
simply use CSS to define the presentation of the page. You could simply
generate a <style type="text/css"> element in the <head> of your HTML
and depending on the conditions put the right CSS rules there so that
the elements are colored as you want it.

--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
Philippe Poulard
Guest
Posts: n/a
 
      07-02-2004
John Kooistra wrote:
> Hi,
>
> I'm trying to set the font colour and background colour in HTML based
> on an XSL condition a la:
>
> <xsl:variable name="font">
> <xsl:choose>
> <xsl:when test="SOME TEST">
> <fontcolour>Red</fontcolour>
> <bgcolour>Blue</bgcolour>
> </xsl:when>
> <xsltherwise>
> <fontcolour>Black</fontcolour>
> <bgcolour>White</bgcolour>
> </xsltherwise>
> </xsl:choose>
> </xsl:variable>
> <td bgcolor="{$font/bgcolour}">
> <font color="{$font/fontcolour}">
> TEXT
> </font>
> </td>
>
> However, I get the error: "Reference to variable or parameter 'font'
> must evaluate to a node list."
>
> I get it because $font is a Result Tree Fragment.
>
> Is there a way to get the functionality I want without using a
> processor dependent function like msxsl:node-set(rtf)?
>
> As a work-around, I'm currently using two separate variables for
> fontcolour and bgcolour complete with their own condition statements.
> Obviously, it is very ugly and I would really appreciate any
> suggestions you have.
>
> Thanks a million,
> John


hi,

you don't need any extension, just use the right way :
when one need an xml-structured variable, just put it as a child of the
root element of your stylesheet, and refers to it by using document('')
the sole constraint is to define a namespace for all your structured
constants :

<xsl:stylesheet xmlns:const="*** My datas ***"
xmlnssl="...as usual">

<const:fonts>
<font>
<fontcolour>Red</fontcolour>
<bgcolour>Blue</bgcolour>
</font>
<font>
<fontcolour>Black</fontcolour>
<bgcolour>White</bgcolour>
</font>
</const:fonts>

<xsl:template ...>
<xsl:variable name="fontNumber">
<xsl:choose>
<xsl:when test="SOME TEST">1</xsl:when>
<xsltherwise>2</xsltherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="font"
select="document('')/*/const:fonts/font[number($fontNumber)]">
<td bgcolor="{$font/bgcolour}">
<font color="{$font/fontcolour}">
TEXT
</font>
</td>
</xsl:template>

</xsl:stylesheet>
--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Valued logic simulation using VHDL? Guru Prasad VHDL 1 09-28-2012 06:47 AM
Frequency spectrum with fft of a real valued array...? Holger Python 2 01-22-2007 01:05 PM
Surveys/Links on how valued ms qualifications are =?Utf-8?B?SmFtZXM=?= Microsoft Certification 1 01-20-2006 12:21 PM
Defining a real valued input in the entity VHDL 1 02-04-2004 08:15 AM
lists with zero-valued elements Nick Forest Python 3 12-27-2003 11:24 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57