xsl-list
[Top] [All Lists]

Re: [xsl] junit test... for xslt2?

2010-03-06 03:27:07
On 06/03/10 08:17, Andrew Welch wrote:
Hi Dave,

On 6 March 2010 05:25, Dave Pawson<davep(_at_)dpawson(_dot_)co(_dot_)uk>  wrote:
Has anyone written any test software for comparing the results of XSLT
actions? E.g. for each of the different data types?

Any suggested approaches? functions? external calls to Java? Other?

Can you provide an example?



This works for what I'm doing. Display is down to the 'driver' which includes this code.
Just returns boolean pass/fail.

<!-- Integer compare -->
  <xsl:function name="d:int-cmp" as="xs:boolean">
    <xsl:param name="n1" as="xs:integer"/>
    <xsl:param name="n2" as="xs:integer"/>
    <xsl:choose>
      <xsl:when test="$n1 = $n2">
        <xsl:value-of select="true()"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="false()"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>

<!-- Double compare -->
 <xsl:function name="d:double-cmp" as="xs:boolean">
    <xsl:param name="n1" as="xs:double"/>
    <xsl:param name="n2" as="xs:double"/>
    <xsl:param name="tolerance" as="xs:double"/>
    <xsl:choose>
      <xsl:when test="abs($n1 - $n2) &lt;= $tolerance">
        <xsl:value-of select="true()"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="false()"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>

<!-- item() compare -->
<xsl:function name="d:item-cmp" as="xs:boolean">
  <xsl:param name="n1" as="item()"/>
  <xsl:param name="n2" as="item()"/>
 <xsl:choose>
      <xsl:when test="$n1 = $n2">
        <xsl:value-of select="true()"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="false()"/>
      </xsl:otherwise>
    </xsl:choose>
</xsl:function>


<!-- Numeric compare (int, real, double etc.  -->
<!-- Convert to double -->

 <xsl:function name="d:numeric-cmp" as="xs:boolean">
    <xsl:param name="n1" as="xs:double"/>
    <xsl:param name="n2" as="xs:integer"/>
    <xsl:param name="tolerance" as="xs:double"/>
    <xsl:variable name="n2d" select="number($n2)" as="xs:double"/>

    <xsl:choose>
      <xsl:when test="abs($n1 - $n2d) &lt;= $tolerance">
        <xsl:value-of select="true()"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="false()"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>


I'm unsure on the last one.
I want to take 'any' numeric format and convert to double
prior to testing.


regards

--
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--