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

RE: xsl:variable question

Subject: RE: xsl:variable question
From: "Chris Bayes" <chris@xxxxxxxxxxx>
Date: Wed, 19 Dec 2001 23:15:46 -0000
RE:  xsl:variable question
> In the second, you try to assign a nodeset 
> consisting of elements named "1", which of course cannot 
> exist since it would be illegal for an element name.

That's not quite true. It assigns a single text node containing '1' to
the variable.
But as the test is a scalar test it compares the node after doing a
normalize-space on it

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:variable name="mode1" select="'1'" />
	<xsl:variable name="mode2">1</xsl:variable>
	
	<xsl:template match="/">	
		<html>
			<body>
				<xsl:if test="$mode1='1'">Mode 1 =
'1'</xsl:if>
				<xsl:if test="$mode2='1'">Mode 2 =
'1'</xsl:if>
				<xsl:if test="$mode2=$mode1">Mode 2 =
Mode 1</xsl:if>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

> for your second comment, since the variable is declared in top level
template, so you 
> do not need to pass the para when calling "dosomething"

That isn't the case. It is not declared at the top level it is declared
in the template that matches "/". Declaring it at the top level means
declaring it at the top level of the stylesheet as I have done above.

If you want to do different things depending on mode you probably want
to have a mode attribute on the template

<xsl:template match="/">
	<xsl:apply-templates select="some_thing" mode="mode1" />
	<xsl:apply-templates select="some_thing" mode="mode2" />
</xsl:template>

<xsl:template match="some_thing" mode="mode1">
	... Do something with some_thing for mode 1
</xsl:template>

<xsl:template match="some_thing" mode="mode2">
	... Do something with some_thing for mode 2
</xsl:template>

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml



 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.