Not wanting to stop the fun!
But here's a 1.0 solution (a complete stylesheet, I wrote and stopped
posting it hours ago when I saw a solution using 'translate' -- which
is far better) to test for hexadecimal values using a
recursive-template method:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:variable name="hexDigits" select="'0123456789ABCDEFabcdef'" />
<xsl:template match="/">
<xsl:variable name="X" select="'#x202f'" />
<xsl:variable name="Y" select="'#x20yf'" />
<xsl:call-template name="isHex">
<xsl:with-param name="value" select="substring-after($X, '#x')" />
</xsl:call-template>
<xsl:text>
</xsl:text>
<xsl:call-template name="isHex">
<xsl:with-param name="value" select="substring-after($Y, '#x')" />
</xsl:call-template>
</xsl:template>
<xsl:template name="isHex">
<xsl:param name="value" />
<xsl:choose>
<xsl:when test="not($value = '')">
<xsl:choose>
<xsl:when test="not(contains($hexDigits,
substring($value, 1, 1)))">
<xsl:value-of select="'false'" />
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="isHex">
<xsl:with-param name="value"
select="substring($value, 2)" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'true'" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
But in 1.0 environment, you should definitely go for the 'translate' solution.
If you can, I encourage to move to a 2.0 environment (unless you are
programming for a browser) :)
On Thu, Aug 26, 2010 at 3:00 PM,
<pankaj(_dot_)c(_at_)thomsondigital(_dot_)com> wrote:
Is there any better way to test hexadecimal values.
--
Regards,
Mukul Gandhi
--~------------------------------------------------------------------
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>
--~--