[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Setting two variables from the result of a "complex" t
Hi, {This started out as a question, but I think I solved my own problem. Because I had to think about it for a bit and because there might be something else that I have realized, I've decided to post it anyways.} I have been contemplating how to make a more efficient solution to a problem that is similar to the one below. (I have simplified my code a lot.) In the BUTTON template that you see below, I am setting two variables based on the result of a test. The test that I have given in my example below is "$Language = 2" (for arguments sake, assume this test is computationally significant). As you can see I need to perform this test twice, once for setting each variable. Since this test is "expensive", I would rather only do it once. Remaining new to XSL my questions are: 1- Is the basic design of the BUTTON template okay? Based on the XSL Frequently Asked Questions site, I am instructed to do "<xsl:variable><xsl:choose>..." for each variable (instead of "<xsl:choose>set each variable inside the choose"). Have I got this right? 2- Assuming that I have got it right, my solution is to create a third variable say "TestResult" that contains the result of the computationally expensive calculation and put the setting of TestResult before the other two variables in the template. Does this make good sense? 3 - I am sure that some uber XSLers might come up with some instances where this idea might not work (some nasty tree fragment or something) -- if that is the case, I wouldn't mind going along for the ride while it is discussed. Thanks a bunch, J. XML - - - - <?xml version="1.0" encoding="UTF-8"?> <MENU> <BUTTON> <ENGLISH_URL>http://www.dpawson.co.uk/xsl/xslfaq.html</ENGLISH_URL> <ENGLISH_TEXT>XSL Frequently Asked Questions</ENGLISH_TEXT> <FRENCH_URL>http://www.fakeFrenchURL.fr/xsl/xslfaq.html</FRENCH_URL> <!-- Please excuse my French --> <FRENCH_TEXT>Des questions frequémment posé sur XSL</FRENCH_TEXT> </BUTTON> </MENU> XSL - - - - <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:output method="html"/> <!-- Global parameters --> <!-- Assume English(1) language if none is specified --> <xsl:param name="Language" select="1"/> <xsl:template match="/"> <html> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="BUTTON"> <xsl:variable name="URL"> <xsl:choose> <xsl:when test="$Language = 2"> <!-- French --> <xsl:value-of select="FRENCH_URL/text()"/> </xsl:when> <xsl:otherwise> <!-- English --> <xsl:value-of select="ENGLISH_URL/text()"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="LinkName"> <xsl:choose> <xsl:when test="$Language = 2"> <!-- French --> <xsl:value-of select="FRENCH_TEXT/text()"/> </xsl:when> <xsl:otherwise> <!-- English --> <xsl:value-of select="ENGLISH_TEXT/text()"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="$URL"/> </xsl:attribute> <xsl:value-of select="$LinkName"/> </xsl:element> <br/> </xsl:template> </xsl:stylesheet> James MacEwan Software Developer Investors Group Inc. mailto:James.MacEwan@xxxxxxxxxxxxxxxxxx v: (204) 956-8515 f: (204) 943-3540 *:-.,_,.-:*'``'*:-.,_,.-:*'``'*:-.,_,.-:*'``'*:-.,_,.-:*'``'*:-.,_,.-:*'``'* :-.,_ "I don't know, lad. It's like no cheese I've ever tasted." -- Wallace *:-.,_,.-:*'``'*:-.,_,.-:*'``'*:-.,_,.-:*'``'*:-.,_,.-:*``'*:-.,_,.-:*'``'*: -.,_ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|