xsl-list
[Top] [All Lists]

RE: [xsl] outputting ampersand to its actual character

2006-09-05 02:55:58
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/


--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>