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

RE: manipulating a property value

Subject: RE: manipulating a property value
From: "Kenny Akridge" <kenny@xxxxxxxxxxxxxxxxx>
Date: Thu, 15 Apr 2004 02:05:33 -0400
xslt property
Yeah, I realize I posted 24 instead of 8.  I guess maybe you were dealing
with 8 hour work days or something of that nature.  I didn't catch that the
first pass.

Glad to help.

-----Original Message-----
From: David Buddrige [mailto:dbuddrige@xxxxxxxxx] 
Sent: Thursday, April 15, 2004 12:51 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  manipulating a property value

Thanks heaps for that Kenny.  8-)

Fyi, the final xslt template was this:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" indent="no"/>
	<xsl:template match="/">
		<myoutput>
			<xsl:apply-templates/>
		</myoutput>
	</xsl:template>
	<xsl:template match="mytag">
		<xsl:element name="mytag">
			<xsl:attribute name="duration">
				<xsl:choose>
					<xsl:when test="contains(@duration,
'days')">
						<xsl:value-of
select="translate(@duration, '
days', '') * 8"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of
select="translate(@duration, '
hours','')"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>


thanks

David.

--- Kenny Akridge <kenny@xxxxxxxxxxxxxxxxx> wrote:
> I don't know how to do this in 2.0, but this works
> for 1.1(I believe it is
> 1.1).
> 
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:template match="/">
> 		<myoutput>
> 			<xsl:apply-templates/>
> 		</myoutput>
> 	</xsl:template>
> 	<xsl:template match="mytag">
> 		<xsl:choose>
> 			<xsl:when test="contains(@duration, 'days')">
> <!-- translate ' days' to empty string, which leaves
> with an int -->
> <xsl:value-of select="translate(@duration, ' days',
> '') * 24"/>
> <br/>
> 			</xsl:when>
> 			<xsl:otherwise>
> <!-- ditto on ' hours' -->	
> 			<xsl:value-of select="translate(@duration, '
> hours',
> '')"/>
> 				<br/>
> 			</xsl:otherwise>
> 		</xsl:choose>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> -----Original Message-----
> From: David Buddrige [mailto:dbuddrige@xxxxxxxxx] 
> Sent: Wednesday, April 14, 2004 10:48 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  manipulating a property value
> 
> Hi all,
> 
> I have the following input document:
> 
> <?xml version="1.0" encoding="iso-8859-1"?>
> <info>
> 	<mytag duration="3 days" />
> 	<mytag duration="4 days" />
> 	<mytag duration="6 hours" />
> 	<mytag duration="33 hours" />
> 	<mytag duration="13 hours" />
> 	<mytag duration="5 days" />
> 	<mytag duration="3 hours" />
> 	<mytag duration="23 hours" />
> </info>
> 
> What I want to do, is to convert the output document
> so that all duration values are in hours, and
> without
> specifying the units.  So where a duration = "3
> days",
> I want to convert it to hours by multiplying it by
> 8,
> and dropping the units identifier.
> 
> Thus
> 
> 	<mytag duration="5 days" />
> 
> becomes
> 
> 	<mytag duration="40"/>
> 
> 
> And also
> 
> 	<mytag duration="6 hours"/>
> 
> becomes
> 
> 	<mytag duration="6"/>
> 
> 
> The xslt template I have written to [attempt] to do
> this is as follows:
> 
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:template match="/">
> 		<myoutput>
> 			<xsl:apply-templates/>
> 		</myoutput>
> 	</xsl:template>
> 	<xsl:template match="mytag">
> 		<xsl:choose>
> 			<xsl:when test="@duration='*days'"><!-- need to
> somehow strip off the 'days' and multiply remaining
> value by 8 --></xsl:when>
> 			<xsl:otherwise><!-- need to somehow strip off the
> 'hours' and return the remaining substring
> --></xsl:otherwise>
> 		</xsl:choose>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> I note that XSLT 2.0 has regular expressions
> available
> that would make this alot easier - is there any way
> to
> do this with XSLT 1.x?
> 
> thanks heaps
> 
> David Buddrige
> 
> 
> 	
> 		
> __________________________________
> Do you Yahoo!?
> Yahoo! Tax Center - File online by April 15th
> http://taxes.yahoo.com/filing.html
> 



	
		
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html

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.