Unicode Code Point Functions

There are two functions in XPath 2.0 designed to work with Unicode code points , which refers to Unicode equivalent of characters . These functions are fn: codepoints -to-string and fn:string-to-codepoints . They're coming up next .

The fn:codepoints-to-string Function

You pass this function a sequence of Unicode code points, and it converts them to a string. Here's how you use this function:

 fn:codepoints-to-string(  $srcval  as xs:integer*) as xs:string 

For example, to convert the Unicode code point sequence (65, 66, 67) into the corresponding string, "ABC", we can use this function as you see in ch10_13.xsl (Listing 10.13).

Listing 10.13 An XSLT Example Using the XPath Function fn:codepoints-to-string ( ch10_13.xsl )
 <xsl:stylesheet version="2.0"     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:xs="http://www.w3.org/2001/XMLSchema">     <xsl:template match="/">  <xsl:value-of select="codepoints-to-string((65, 66, 67))"/>  </xsl:template> </xsl:stylesheet> 

And here is the result:

 <?xml version="1.0" encoding="UTF-8"?> ABC 

The fn:string-to-codepoints Function

This function lets you create a sequence of Unicode code points from a string. Here's how you use this function:

 fn:string-to-codepoints(  $srcval  as xs:string) as xs:integer* 

You can see an example in ch10_14.xsl in Listing 10.14, where we're converting the string "ABC" to a sequence of code points, and displaying that sequence by using the separator attribute in the <xsl:value-of> element.

Listing 10.14 An XSLT Example Using the XPath Function fn:string-to-codepoints ( ch10_14.xsl )
 <xsl:stylesheet version="2.0"     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:xs="http://www.w3.org/2001/XMLSchema">     <xsl:template match="/">  <xsl:value-of select="string-to-codepoints('ABC')" separator=", "/>  </xsl:template> </xsl:stylesheet> 

And here's the resultas you can see, we've been able to convert "ABC" into a sequence of code points:

 <?xml version="1.0" encoding="UTF-8"?> 65, 66, 67 

XPath. Navigating XML with XPath 1.0 and 2.0 Kick Start
XPath Kick Start: Navigating XML with XPath 1.0 and 2.0
ISBN: 0672324113
EAN: 2147483647
Year: 2002
Pages: 131

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net