XSLT HTML

I would like to convert some value from an XML attribute to valid HTML with entities. So, for example, the string "olá" from XML will be converted from XSLT to "olá"

I can not find any xsl function for this. Any ideas?

+4
source share
2 answers

You can specify us-ascii encoding in the xsl:stylesheet element. Next 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 a standard XML header.

+4
source

I am sure you will find this template useful: Download this xslt and check out the one called url-encode-num http://advanced-internal-onebox.googlecode.com/files/obox_stylesheet.xslt

It converts any special character ... Well, any of those 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 easy to upgrade.

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

Pablo

0
source

Source: https://habr.com/ru/post/1305470/


All Articles