XML/XSLT stylesheet/div
divsion between date value
<source lang="xml">
File: Data.xml
File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:variable name="yMD1" as="xs:yearMonthDuration" select="xs:yearMonthDuration("P1Y8M")"/> <xsl:variable name="yMD2" as="xs:yearMonthDuration" select="xs:yearMonthDuration("P0Y5M")"/> <xsl:variable name="dTD1" as="xs:dayTimeDuration" select="xs:dayTimeDuration("P24DT08H00M00S")"/> <xsl:variable name="dTD2" as="xs:dayTimeDuration" select="xs:dayTimeDuration("P0DT4H00M00S")"/> <xsl:template match="/"> <xsl:text>More tests of division in XPath 2.0:</xsl:text> <xsl:text> A xs:yearMonthDuration divided </xsl:text> <xsl:text>by a number: </xsl:text> <xsl:value-of select="($yMD1, "div 4 =", $yMD1 div 4)"/> <xsl:text> One xs:yearMonthDuration divided </xsl:text> <xsl:text>by another: </xsl:text> <xsl:value-of select="($yMD1, "div", $yMD2, "=", $yMD1 div $yMD2)"/> <xsl:text> A xs:dayTimeDuration divided </xsl:text> <xsl:text>by a number: </xsl:text> <xsl:value-of select="($dTD1, "div 4.5 =", $dTD1 div 4.5)"/> <xsl:text> One xs:dayTimeDuration divided </xsl:text> <xsl:text>by another: </xsl:text> <xsl:value-of select="($dTD1, "div", $dTD2, "=", $dTD1 div $dTD2)"/> </xsl:template>
</xsl:stylesheet> Output: More tests of division in XPath 2.0:
A xs:yearMonthDuration divided by a number: P1Y8M div 4 = P5M One xs:yearMonthDuration divided by another: P1Y8M div P5M = 4 A xs:dayTimeDuration divided by a number: P24DT8H div 4.5 = P5DT9H46M40S One xs:dayTimeDuration divided by another: P24DT8H div PT4H = 146 </source>
Tests of XPath div in XSLT 1.0
<source lang="xml">
File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>Tests of XPath div in XSLT 1.0 </xsl:text> <xsl:text> 9 div 3 = </xsl:text> <xsl:value-of select="9 div 3"/> <xsl:text> 9 div 3.8 = </xsl:text> <xsl:value-of select="9 div 3.8"/> <xsl:text> 9 div "4" = </xsl:text> <xsl:value-of select="9 div "4""/> <xsl:text> 9 div "Q" = </xsl:text> <xsl:value-of select="9 div "Q""/> <xsl:text> 9 div true() = </xsl:text> <xsl:value-of select="9 div true()"/> <xsl:text> 9 div false() = </xsl:text> <xsl:value-of select="9 div false()"/> </xsl:template>
</xsl:stylesheet> Output: Tests of XPath div in XSLT 1.0
9 div 3 = 3 9 div 3.8 = 2.368421052631579 9 div "4" = 2.25 9 div "Q" = NaN 9 div true() = 9 9 div false() = INF </source>
Tests of XPath div in XSLT 2.0
<source lang="xml">
File: Data.xml
File: Transform.xslt <?xml version="1.0"?> <xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>Tests of XPath div in XSLT 2.0 </xsl:text> <xsl:text> 9 div 3 = </xsl:text> <xsl:value-of select="9 div 3"/> <xsl:text> 9 div 3.8 = </xsl:text> <xsl:value-of select="9 div 3.8"/> <xsl:text> 9 div number("4") = </xsl:text> <xsl:value-of select="9 div number("4")"/> <xsl:text> 9 div number("Q") = </xsl:text> <xsl:value-of select="9 div number("Q")"/> <xsl:text> 9 div number(true()) = </xsl:text> <xsl:value-of select="9 div number(true())"/> <xsl:text> 9 div number(false()) = </xsl:text> <xsl:value-of select="9 div number(false())"/> </xsl:template>
</xsl:stylesheet> Output: Tests of XPath div in XSLT 2.0
9 div 3 = 3 9 div 3.8 = 2.368421052631578947 9 div number("4") = 2.25 9 div number("Q") = NaN 9 div number(true()) = 9 9 div number(false()) = INF </source>