Skip to content

Instantly share code, notes, and snippets.

@kana
Created August 1, 2008 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kana/3631 to your computer and use it in GitHub Desktop.
Save kana/3631 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Usage: xsltproc cho45-problem.xslt cho45-problem.xslt
Problem: http://twitter.com/cho45/statuses/874759595
From "3.4 Booleans"
in "XML Path Language (XPath) Version 1.0 W3C Recommendation 16 November 1999"
<http://www.w3.org/TR/1999/REC-xpath-19991116>,
When neither object to be compared is a node-set and the operator is <=, <,
>= or >, then the objects are compared by converting both objects to numbers
and comparing the numbers according to IEEE 754.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:variable name="NL" select="'&#x0A;'"/>
<xsl:template match="/">
<xsl:call-template name="test">
<xsl:with-param name="a" select="1"/>
<xsl:with-param name="b" select="2"/>
</xsl:call-template>
<xsl:call-template name="test">
<xsl:with-param name="a" select="'1'"/>
<xsl:with-param name="b" select="'2'"/>
</xsl:call-template>
<xsl:call-template name="test">
<xsl:with-param name="a" select="'1 1'"/>
<xsl:with-param name="b" select="'2 2'"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="test">
<xsl:param name="a"/>
<xsl:param name="b"/>
<xsl:value-of select="$NL"/>
<xsl:if test="$a = $b">
<xsl:value-of select="$a"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="$b"/>
<xsl:value-of select="$NL"/>
</xsl:if>
<xsl:if test="$a != $b">
<xsl:value-of select="$a"/>
<xsl:text> != </xsl:text>
<xsl:value-of select="$b"/>
<xsl:value-of select="$NL"/>
</xsl:if>
<xsl:if test="$a &lt; $b">
<xsl:value-of select="$a"/>
<xsl:text> &lt; </xsl:text>
<xsl:value-of select="$b"/>
<xsl:value-of select="$NL"/>
</xsl:if>
<xsl:if test="$a &lt;= $b">
<xsl:value-of select="$a"/>
<xsl:text> &lt;= </xsl:text>
<xsl:value-of select="$b"/>
<xsl:value-of select="$NL"/>
</xsl:if>
<xsl:if test="$a &gt; $b">
<xsl:value-of select="$a"/>
<xsl:text> &gt; </xsl:text>
<xsl:value-of select="$b"/>
<xsl:value-of select="$NL"/>
</xsl:if>
<xsl:if test="$a &gt;= $b">
<xsl:value-of select="$a"/>
<xsl:text> &gt;= </xsl:text>
<xsl:value-of select="$b"/>
<xsl:value-of select="$NL"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment