[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: junit test... for xslt2?

Subject: Re: junit test... for xslt2?
From: Dave Pawson <davep@xxxxxxxxxxxxx>
Date: Sat, 06 Mar 2010 09:24:55 +0000
Re:  junit test... for xslt2?
On 06/03/10 08:17, Andrew Welch wrote:
Hi Dave,

On 6 March 2010 05:25, Dave Pawson<davep@xxxxxxxxxxxxx> 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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.