开发者

HTML encode on a XSLT

I would like to convert some value from a XML attribute into valid HTML with entities. So that for example the string "olá" from the XML would be transformed from the XSLT into "olá"

I can't find any xsl function to do this.开发者_开发百科 Any ideas ?


You can specify us-ascii encoding in xsl:stylesheet element. The following XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="html" encoding="us-ascii"/>

    <xsl:variable name="data" select="'olá'" />

    <xsl:template match="/">
        <xsl:text>olá - </xsl:text>
        <xsl:value-of select="$data" />
    </xsl:template>
</xsl:stylesheet>

gives:

ol&#225; - ol&#225;

The xml method in xsl:stylesheet gives the same result with the standard XML heading.


I´m pretty sure you´ll find this template useful: Download this xslt and check the one called "url-encode-num" http://advanced-internal-onebox.googlecode.com/files/obox_stylesheet.xslt

It transforms any special character... Well, any of the ones listed here with their numeric encodings:

<xsl:variable name="latbis">¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"&lt;&gt;=</xsl:variable>
<xsl:variable name="digit1">111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222220000</xsl:variable>
<xsl:variable name="digit2">666666666777777777788888888889999999999000000000011111111112222222222333333333344444444445555552777</xsl:variable>
<xsl:variable name="digit3">123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123452465</xsl:variable>

But is easy to update.

Let me know if this is what you were looking for.

Pablo

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜