xsl-list
[Top] [All Lists]

manipulating a property value

2004-04-14 19:48:06
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


<Prev in Thread] Current Thread [Next in Thread>