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

Problem with Variables

Subject: Problem with Variables
From: "Gerald Fingerlos" <gerald@xxxxxxxxxxxx>
Date: Mon, 02 Feb 2004 15:38:31 +0100
xsl problem with variables
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

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.