[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

translate()-function (Xalan)

Subject: translate()-function (Xalan)
From: Peter Paulus <paulus@xxxxxxxx>
Date: Tue, 15 Aug 2000 14:32:33 +0200
xalan translate
Hi,

In our application, the resulting 'xml' should have several different
character encodings. The exact encoding depends on the font being used.

The input xml always contains 'Unicode' encoding.

Ideally one would like to use the 'encoding' attribute on the
<xsl:output>-element. But this has several disadvantages:
1. The result encoding is non-standard. Several encoders would have to be
programmed.
2. There is no a priori knowledge about the exact fonts that are going to be
used.
3. It looks to me that you can select only 1 output encoding, whereas I
would need several.

Alternatively one could use the (XPath) translate()-function. I started out
with a 'hardcoded' <xsl:value-of select='translate(., "&#xE9;", "&#x8E;")'/>
or <xsl:value-of select='translate(title, "&#xE9;", "&#x8E;")'/>. This
works.

However, (worst case) I will need, say up to 10 different encodings in the
resulting xml. My example only contains a single mapping. In real life there
will somewhere around 30 mappings per encoding.

So, I figured, why not put the encodings in global variables and pass those
to the xpath function translate(). Here's what I did:

<?xml version='1.0' encoding='ISO-8859-1'?>
<xsl:transform version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output method='xml' encoding='ISO-8859-1' omit-xml-declaration='no'
media-type='application/qxml'/>

<xsl:variable name='Unicode_Encoding'>&#xE9;</xsl:variable>
<xsl:variable name='FontXYZ_Encoding'>&#x8E;</xsl:variable>

<xsl:template match='/'>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match='journey/title[@level = 1]'>
<paragraph style='Caption 1'>
<xsl:value-of select='translate(., "{Unicode_Encoding}",
"{FontXYZ_Encoding}")'/>
<xsl:if test='position() != last()'><br/></xsl:if>
</paragraph>
</xsl:template>

</xsl:transform>

This indeed does translate() something: every U becomes F, every e becomes
Z. translate() interprets the second and third argument as literal strings.
How can one pass the variables to the translate function?

Are there any other alternatives in achieving the encoding mappings?

With kind regards,
Peter Paulus


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.