Subject: Re: [xsl] junit test... for xslt2? From: Dave Pawson <davep@xxxxxxxxxxxxx> Date: Sat, 06 Mar 2010 09:24:55 +0000 |
Hi Dave,This works for what I'm doing. Display is down to the 'driver' which includes this code.
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?
<!-- 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) <= $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) <= $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.
-- Dave Pawson XSLT XSL-FO FAQ. http://www.dpawson.co.uk
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] junit test... for xslt2?, Andrew Welch | Thread | Re: [xsl] junit test... for xslt2?, Andrew Welch |
Re: [xsl] junit test... for xslt2?, Tony Graham | Date | Re: [xsl] junit test... for xslt2?, Dave Pawson |
Month |