Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Functions operating on strings (15/15) >

Strings from unicode codepoints

The function string-to-codepoints() creates a sequence of unicode codepoints corresponding to the characters in the string provided in the argument.

The function codepoints-to-string() performs the reverse operation. It creates a string from a sequence of unicode codepoints.

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/aaa">
                  <xxx>
                        <xsl:value-of  select="string-to-codepoints(bbb)"/>
                  </xxx>
                  <yyy>
                        <xsl:value-of  select="codepoints-to-string((72,101,108,108,111))"/>
                  </yyy>
                  <zzz>
                        <xsl:for-each  select="for $a in (1 to 10) return (48+$a*5)">
                              <item  char="{codepoints-to-string(.)}"
                                          code="{.}"/>
                        </xsl:for-each>
                  </zzz>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb>Hello</bbb>
      </aaa>
Output

      <xxx>72 101 108 108 111</xxx>
      <yyy>Hello</yyy>
      <zzz>
            <item  char="5"
                        code="53"/>
            <item  char=":"
                        code="58"/>
            <item  char="?"
                        code="63"/>
            <item  char="D"
                        code="68"/>
            <item  char="I"
                        code="73"/>
            <item  char="N"
                        code="78"/>
            <item  char="S"
                        code="83"/>
            <item  char="X"
                        code="88"/>
            <item  char="]"
                        code="93"/>
            <item  char="b"
                        code="98"/>
      </zzz>


Previous chapter: Arithmetics
Next chapter: Transforming strings with regular expressions
Previous page: Escaping of URI with encode-for-uri, iri-to-uri, and escape-html-uri
Next page: - - -