The very same simple tasks tend to appear in different languages (e.g. C# Haiku). Now we have to find:
These tasks have no trivial solutions in xslt 2.0.
At present we have came up with the following answers:
Fractional part:
<xsl:function name="t:fraction" as="xs:decimal"> <xsl:param name="value" as="xs:decimal"/> <xsl:sequence select="$value mod 1"/> </xsl:function>
Integer part v1:
<xsl:function name="t:integer" as="xs:decimal"> <xsl:param name="value" as="xs:decimal"/> <xsl:sequence select="$value - t:fraction($value)"/> </xsl:function>
Integer part v2:
<xsl:function name="t:integer" as="xs:decimal"> <xsl:param name="value" as="xs:decimal"/> <xsl:sequence select=" if ($value ge 0) then floor($value) else -floor(-$value)"/> </xsl:function>
Length and precision:
<!-- Gets a decimal specification as a closure: ($length as xs:integer, $precision as xs:integer). --> <xsl:function name="t:decimal-spec" as="xs:integer+"> <xsl:param name="value" as="xs:decimal"/> <xsl:variable name="text" as="xs:string" select=" if ($value lt 0) then xs:string(-$value) else xs:string($value)"/> <xsl:variable name="length" as="xs:integer" select="string-length($text)"/> <xsl:variable name="integer-length" as="xs:integer" select="string-length(substring-before($text, '.'))"/> <xsl:sequence select=" if ($integer-length) then ($length - 1, $length - $integer-length - 1) else ($length, 0)"/> </xsl:function>
The last function looks odious. In many other languages its implementation would be considered as embarrassing.