Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

MathOps: simple math operations in xslt

cfMathOps.xml:
   1  
   2  <?xml version="1.0" ?>
   3  <?xml-stylesheet type="text/xsl" href="cfMathOps.xsl" ?>
   4  <!--
   5  ### begin_: file metadata
   6      ### <region-file_info>
   7      ### main:
   8      ###   - name : cfMathOps.xml
   9      ###     desc : xml data file to use with cfMathOps.xsl
  10      ###     date : created="Thu 2005-12-01 11:57:38"
  11      ###     last : lastmod="Thu 2005-12-01 11:57:41"
  12      ###     lang    : xslt
  13      ###     tags    : xml xslt math cfMathOps
  14      ### </region-file_info>
  15      -->
  16  <numbers>
  17    <x>4</x>
  18    <y>3.2</y>
  19    <z>11</z>
  20  </numbers>


cfMathOps.xsl
   1  
   2  <xsl:stylesheet
   3      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   4  <!--
   5  ### begin_: file metadata
   6      ### <region-file_info>
   7      ### main:
   8      ###   - name : cfMathOps.xsl
   9      ###     desc : quick example of math operations using xslt
  10      ###     date : created="Thu 2005-12-01 11:57:38"
  11      ###     last : lastmod="Thu 2005-12-01 11:57:41"
  12      ###     lang    : xslt
  13      ###     tags    : xml xslt math hello cfMathOps
  14      ### </region-file_info>
  15      -->
  16  
  17  <xsl:output method="html" omit-xml-declaration="yes"/>
  18  
  19  <xsl:template match="numbers">
  20  <h2>math operations from xslt</h2>
  21      <br />  A. 4 + 3.2        = <xsl:value-of select="x + y"/>
  22      <br />  B. 3.2 - 4        = <xsl:value-of select="y - x"/>
  23      <br />  C. 4 * 3.2        = <xsl:value-of select="x * y"/>
  24      <br />  D. 11/3.2         = <xsl:value-of select="z div y"/>
  25      <br />  E. 4 + 3.2 * 11   = <xsl:value-of select="x+y*z"/>
  26      <br />  F. (4 + 3.2) * 11 = <xsl:value-of select="(x+y)*z"/>
  27      <br />  G. 11 mod 4       = <xsl:value-of select="z mod x"/>
  28      <br />  H. 4 + 3.2 + 11   = <xsl:value-of select="sum(*)"/>
  29      <br />  I. floor(3.2)     = <xsl:value-of select="floor(y)"/>
  30      <br />  J. ceiling(3.2)   = <xsl:value-of select="ceiling(y)"/>
  31      <br />  K. round(3.2)     = <xsl:value-of select="round(y)"/>
  32      <br />  L. 11 + count(*)  = <xsl:value-of select="11+count(*)"/>
  33      <br />  M. 11 + "hello"                 = <xsl:value-of select="z + 'hello'"/>
  34      <br />  N. 3.2 + string-length("3.2")   = <xsl:value-of select="y + string-length(y)"/>
  35  </xsl:template>
  36  
  37  </xsl:stylesheet>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS