Subject: RE: [xsl] manipulating a property value From: "Kenny Akridge" <kenny@xxxxxxxxxxxxxxxxx> Date: Thu, 15 Apr 2004 02:05:33 -0400 |
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: [xsl] 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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] manipulating a property v, David Buddrige | Thread | [xsl] how do you determine if a pro, David Buddrige |
RE: [xsl] manipulating a property v, David Buddrige | Date | [xsl] how do you determine if a pro, David Buddrige |
Month |