开发者

converting hexacode in html to xml

I开发者_C百科 am converting html to xml using xslt1.0.This is a fragment of my html:

<span style="font-family: Wingdings;>
        
  </span>

My output should be,

<w:sym w:font="Wingdings" w:char="F0D8"/>

Is it possible to do it in xslt or using java.How to identify the char code inside span? Thanks in advance..


This XSLT 2.0 solution:

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

 <xsl:template match="/*">
     <xsl:value-of select=
     "my:dec-to-hex(string-to-codepoints(normalize-space()))"/>
 </xsl:template>

 <xsl:variable name="vHexDigits" select="'0123456789ABCDEF'"/>

 <xsl:function name="my:dec-to-hex" as="xs:string">
  <xsl:param name="pDec" as="xs:integer"/>

  <xsl:variable name="vQuot" select="$pDec idiv 16"/>
  <xsl:variable name="vRemainder" select="$pDec mod 16"/>

  <xsl:sequence select=
   "if($pDec lt 16)
     then substring($vHexDigits, $pDec+1, 1)
     else
      concat(my:dec-to-hex($vQuot),
             substring($vHexDigits, $vRemainder+1, 1)
             )
   "/>

 </xsl:function>
</xsl:stylesheet>

when applied to the provided XML document:

<span style="font-family: Wingdings;">            </span>

produces exactly the wanted hexadecimal representation:

F0D8
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜