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

RE: outputting ampersand to its actual character

Subject: RE: outputting ampersand to its actual character
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 5 Sep 2006 10:55:43 +0100
ampersand hex
> In my variable I have to convert these lines to:
> <entry><search>&#x0061;&#x00E0;</search><replace>&#x1F05;</rep
> lace></entry>
> <entry><search>&#x0065;&#x00E0;</search><replace>&#x1F15;</rep
> lace></entry>
> and my problem is, whenever is try to replace '\' with an 
> &#x62;#x I end up with &amp;#x

A variable contains a tree of nodes, it doesn't contain lexical XML. I
assume you want your first "search" element to contain two characters, the
characters with Unicode codepoints x61 and xE0. To achieve that, you want to
write those two characters, not some XML markup that an XML parser would
convert into those characters. To write these two characters you can use

<xsl:value-of select="codepoints-to-string((97, 224))"/>

if I've got my sums right.

Your stylesheet needs to do the hex-to-decimal conversion: here's a function
I wrote to do this:

 <xsl:function name="f:hex-to-char" as="xs:integer">
   <xsl:param name="in"/> <!-- e.g. 030C -->
   <xsl:sequence select="
   if (string-length($in) eq 1)
      then f:hex-digit-to-integer($in)
      else 16*f:hex-to-char(substring($in, 1, string-length($in)-1)) + 
             f:hex-digit-to-integer(substring($in, string-length($in)))"/>
 </xsl:function>

 <xsl:function name="f:hex-digit-to-integer" as="xs:integer">
   <xsl:param name="char"/>
   <xsl:sequence select="string-length(substring-before('0123456789ABCDEF',
$char))"/>
 </xsl:function>

Michael Kay
http://www.saxonica.com/

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-2013 All Rights Reserved.