Use math function from Java library : extension « XSLT stylesheet « XML






Use math function from Java library


File: Data.xml

<?xml version="1.0"?>
<number>2.0</number>

File: Transform.xslt


<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xs" version="2.0">

  <xsl:template match="number">
    <result>
      <xsl:value-of select="Math:sqrt(xs:double(.))"
        xmlns:Math="java:java.lang.Math" />
    </result>
  </xsl:template>

</xsl:transform>

Output:

<?xml version="1.0" encoding="UTF-8"?><result>1.4142135623730951</result>

 








Related examples in the same category

1.Java extension
2.Define function in VBscript