473,219 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,219 software developers and data experts.

XSLT: Converting a number into a character?

I have a need to convert a number into the character that it
represents.

For example, if I have:

<xsl:variable name="number" select="169"/>

I want to be able to convert this to the character which is
represented by the number( in this example, it would be the hardcoded
character © the copyright character) for output.

What I would like to do is something like:

<xsl:value-of select="character( $number )"/>

where the value-of returns a single character to the output stream (in
this case the copyright character). But there is no such function as
character() that I have been able to find.

There doesn't seem to be an obvious way of doing this in XSLT.

Any ideas on how to do this?

Thanks!

.....Andrzej

NOTE: Remove Spamicide(tm) before replying!!!
Jul 20 '05 #1
3 10228
Andrzej Jan Taramina <an*****@chaeron.spamicide.com> writes:
I have a need to convert a number into the character that it
represents. ...>
What I would like to do is something like:

<xsl:value-of select="character( $number )"/>
...
There doesn't seem to be an obvious way of doing this in XSLT.


When I need to do this, I do it this way:

<xsl:variable name="ascii">.......<!--*
*-->.. .. ..<!--*
*-->........<!--*
*-->........<!--*
*--> !"#$%&'<!--*
*-->()*+,-./<!--*
*-->01234567<!--*
*-->89:;<=>?<!--*
*-->@ABCDEFG<!--*
*-->HIJKLMNO<!--*
*-->PQRSTUVW<!--*
*-->XYZ[\]^_<!--*
*-->`abcdefg<!--*
*-->hijklmno<!--*
*-->pqrstuvw<!--*
*-->xyz{|}~</xsl:variable>

....

<xsl:value-of select="substring($ascii,$number,1)"/>

There may be more elegant ways; in the meantime, I hope this helps.

-C. M. Sperberg-McQueen
Jul 20 '05 #2
In article <lg********************************@4ax.com>,
Andrzej Jan Taramina <an*****@chaeron.spamicide.com> wrote:
I have a need to convert a number into the character that it What I would like to do is something like:

<xsl:value-of select="character( $number )"/>

where the value-of returns a single character to the output stream (in
this case the copyright character). But there is no such function as
character() that I have been able to find.


Annoying, isn't it :-)

You could use a string of all the (necessary) characters as Michael
suggests, or you could do something like:

<xsl:text disable-output-escaping="yes">&amp;#</xsl:text>
<xsl:value-of select="$number"/>
<xsl:text>;</xsl:text>

which is, of course, an even grosser hack, but has the advantage of
not requiring a very long string if you use arbitrary Unicode characters.

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #3
On 29 Jan 2004 23:08:15 GMT, ri*****@cogsci.ed.ac.uk (Richard Tobin) wrote:
Annoying, isn't it :-)

You could use a string of all the (necessary) characters as Michael
suggests, or you could do something like:
That won't work since I do not know what range the character code will be in,
and since it's Unicode....building the lookup table would be huge!
<xsl:text disable-output-escaping="yes">&amp;#</xsl:text>
<xsl:value-of select="$number"/>
<xsl:text>;</xsl:text>

which is, of course, an even grosser hack, but has the advantage of


This doesn't work either, since I'm in a Cocoon pipeline which is just
propagating SAX events. The XML is never written out! What your suggestion
will do (I tried it before I posted my initial request) is write "ʞ" into
the SAX stream, which will NOT work for my needs, since I actually need the
single character written out.

That being said, I did find a quick/elegant solution when using Xalan. I used a
Xalan extension to enable me to call a core Java class to do the code to
character conversion for me. The callable template (charUtilities.xsl) looks
somewhat like this:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:char="http://xxx.com/char"
xmlns:charUtil="http://xxx.com/charUtil"
extension-element-prefixes="char charUtil">

<xalan:component prefix="charUtil">
<xalan:script lang="javaclass" src="xalan://java.lang.Character"/>
</xalan:component>

<xsl:template name="char:convertNumber">
<xsl:param name="number" select="'160'" />

<xsl:value-of select="charUtil:new( number( $number ) )"/>
</xsl:template>
</xsl:stylesheet>
To then use the conversion template you do something like the following:

<xsl:import href="charUtilities.xsl" />

......

<xsl:call-template name="char:convertNumber">
<xsl:with-param name="number" select="670"/>
</xsl:call-template>
The only real downside with this approach is that you end up tied to Xalan,
which in my case is not a big deal.
.....Andrzej

NOTE: Remove Spamicide(tm) before replying!!!
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Charles Chow | last post by:
Any clue on why I got this error when I use javascript function in XSLT? The same javescript works fine with ASP. What this function does is to keep only one window (with media player activeX...
2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
2
by: Lionel Fourquaux | last post by:
In .Net 1.1, System.Xml.Xsl.XslTransform cannot output directly a document in an encoding that cannot represent all the characters used (e.g. write in us-ascii for compatibility, and convert all...
2
by: Sharkie | last post by:
I'm relatively new to XSLT, having strong background in bunch of other programming languages (Perl, Java, etc.). I'm writing an XSLT stylesheet, converting XML into HTML. Everything works just...
2
by: jkflens | last post by:
Hello, i convert one XML-document by using XSLT into another XML-document. First change all attributes to elements is no problem. Then i try to insert a new element into the new document by...
6
Robbie
by: Robbie | last post by:
Hi again all, here's something I'm stuck on... I'm making a function to convert a unicode character into the kind of code you need to put on a UTF-8 encoded web page (ampersand, hash, digits,...
15
by: allthecoolkidshaveone | last post by:
I want to convert a string representation of a number ("1234") to an int, with overflow and underflow checking. Essentially, I'm looking for a strtol() that converts int instead of long. The...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.