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]
Other format: [Raw text]

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


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