[xsl] Problem with Variables

Subject: [xsl] Problem with Variables
From: "Gerald Fingerlos" <gerald@xxxxxxxxxxxx>
Date: Mon, 02 Feb 2004 15:38:31 +0100
I am writing a stylesheet which makes a conversion of a date. ie:
1.3.2003 should become 2003.03.01
 
This is my XML Document (truncated), which contains the date
(dd.mm.yyyy)
 
<add-attr attr-name="mozDateChangeState">
    <value type="string">16.2.2003</value>
</add-attr>


And this is my Stylesheet which almost works:

<?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 indent="yes"/>
	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template
match="add-attr[@attr-name='mozDateChangeState']">
		<xsl:variable name="date" select="./value"/>
		<xsl:variable name="dd"
select="substring-before($date,'.')"/>
		<xsl:variable name="mmyy"
select="substring-after($date,'.')"/>
		<xsl:variable name="mm"
select="substring-before($mmyy,'.')"/>
		<xsl:variable name="yyyy"
select="substring-after($mmyy,'.')"/>
		<xsl:choose>
			<xsl:when test="number(string-length($dd) =
1)">
				<xsl:variable name="ddn"
select="concat('0',$dd)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="ddn" select="$dd"/>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="number(string-length($mm) =
1)">
				<xsl:variable name="mmn"
select="concat('0',$mm)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="mmn" select="$mm"/>
			</xsl:otherwise>
		</xsl:choose>
		<add-attr attr-name="mozDateChangeState">
			<value type="string">
				<xsl:value-of
select="concat($yyyy,'.',$mmn,'.',$ddn)"/>
			</value>
		</add-attr>
	</xsl:template>
</xsl:stylesheet>

Everything does work with one exception. Every variable is filled
correctly, but not the variables ddn and mmn, although the xsl:choose
does work correctly. I think its just something I do not consider.
Any hint?
Thank you in advance,
Gerald

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread