tags:

views:

147

answers:

2

I have a element in XML: <duration>00:08:90</duration>. I am using XSLT to create a XML with elements required for my system.

Firstly I want my XSLT to remove the colons to look like this: 000890 Then I want to do a if-test to check whether this number is less than (<) 001000

+3  A: 

You can use the translate function to remove the colons:

translate(., ':', '')

then for the number value checking you can do the following:

number(.) < 1000

so if the xml was like:

<xml>
    <tag>00:08:90</tag>
</xml>

Then you could have the following XSLT:

<xsl:variable name="test" select="number(translate(/xml/tag, ':', '')) &lt; 1000" />
<!-- $test will = true() -->

Check out this zvon xslt number function reference for the acceptable values for number() to do the correct error checking.

null
+1 Beat me to it. ;-)
Tomalak
superb post .. :-) +1 .. got to learn new things ..
infant programmer
A: 
<xsl:if test="number(translate(duration, ':', '')) &lt; 1000">
  <!-- do something -->
</xsl:if>

Unless there is no way for the duration value to be invalid/mis-formatted, pay extra attention to it's length and also to 'NaN' values that could be returned by number().

Tomalak