Re: [xsl] Best way of testing Hexadecimal value [xslt 1.0]

Subject: Re: [xsl] Best way of testing Hexadecimal value [xslt 1.0]
From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Thu, 26 Aug 2010 12:19:11 +0200
>  <xsl:when test=".= 'BULLET SIGN'"> doesn't seems to be nice to me.

Perhaps you want something like 1c) from [1].


> Is there any better way to test hexadecimal values.

This is an old techniques (see [2] for the removal):
  test="translate(.'0123456789abcdefABCDEF','')='')"
It tests the current node for consisting of hexadecimal characters only.


> Apart from this is there a way of testing whether string is a digit
> or character <label>1.</label> <label>a.</label>.

  test="translate(.'0123456789abc.....yzABC.....YZ','')='')"
tests for the current node consisting of digits or characters.
You may want to add "and string-length()=1" to that.


> I believe  <xsl:when test=".='BULLET SIGN'"> will check for the literal
> string instead of something like [A-Za-z0-9]. I am using XSLT 1.0.

Yes, it tests for the single literal value '.'


[1]
http://www.xml.org/sites/www.xml.org/files/xslt_efficient_programming_techniques.pdf
[2] http://www.w3.org/TR/xpath/#function-translate


Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Developer, XML Compiler, L3
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294



From:       pankaj.c@xxxxxxxxxxxxxxxxxx
To:         xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Date:       08/26/2010 11:31 AM
Subject:    [xsl] Best way of testing Hexadecimal value [xslt 1.0]



Hello all,

I just did the following test for one of the requirement in my stylesheet.
Though I am able to get the correct result but somehow I am not convinced
with the approach. There must be better/correct way of doing this.

source
=====
<label>#x2022</label><!--  HEXADECIMAL FOR BULLET  ACTUALLY WITH
'AMPERSAND' AND ; ADDED TO IT -->

Test
====
  <xsl:template match="label">
 <xsl:copy>
        <xsl:choose>
        <xsl:when test=".='.'"><!-- ='.' IS LITERAL BULLET SYMBOL  -->
        <!--  Do Something here  -->
        </xsl:when>
        <xsl:when test=".!='.'"><!-- ='.' IS LITERAL BULLET SYMBOL  -->
        <!--  Do Something different here  -->
        </xsl:when>
    </xsl:choose>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:when test=".= 'BULLET SIGN'"> doesn't seems to be nice to me. Is
there any better way to test hexadecimal values.
Apart from this is there a way of testing whether string is a digit or
character <label>1.</label> <label>a.</label>.

Not tested:

I believe  <xsl:when test=".='BULLET SIGN'"> will check for the literal
string instead of something like [A-Za-z0-9]. I am using XSLT 1.0.

Any thoughts will be appreciated.

TIA,
Pankaj

Current Thread