xsl-list
[Top] [All Lists]

RE: manipulating a property value

2004-04-14 19:59:59
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(_at_)yahoo(_dot_)com] 
Sent: Wednesday, April 14, 2004 10:48 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




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