xsl-list
[Top] [All Lists]

RE: [xsl] Some entities output as entities and others as chars not looking good in the html.. why?

2011-12-13 13:28:02
Alex,

This is probably happening because your output encoding is set to something too 
inclusive for your destination output. The XSLT processor sees Ü, etc. as 
the literal character, so if the output encoding (e.g. UTF-8) supports that 
character, it will output the character directly instead of outputting the 
entity.

If the characters you're searching are the same characters as the entities 
you're replacing with, odds are that you don't even need this series of 
replacements if you restrict the output encoding to begin with. If you want to 
make all characters above \x7F output as entities (not a bad choice for HTML 
output), just use <xsl:output method="html" encoding="US-ASCII" />. Then it's 
up to the XSLT processor to choose how to serialize the output. And as such, if 
you tell it to output a string with those characters, even using a simple 
<xsl:value-of/>, it will know that the extended character isn't valid in 
US-ASCII, and so it will output an entity instead.

Hopefully that helps. Switching the output encoding to US-ASCII has solved many 
similar problems in my experience. As long as the output method is not "text", 
the XSLT processor has options for serializing as entities, and you're safe.

~ Scott


-----Original Message-----
From: Alex Muir [mailto:alex(_dot_)g(_dot_)muir(_at_)gmail(_dot_)com] 
Sent: Tuesday, December 13, 2011 12:03 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Some entities output as entities and others as chars not looking 
good in the html.. why?

Hi,

I've got some currently inefficient code that is to convert some characters to 
entites for html output like so. Will move this into a analyze string function 
with a lookup later, but the problem other than speed is that some of the 
characters are not being replaced as entities.

...replace(replace(replace(replace(replace(replace(replace(replace(
      $arg,'?','&#146;'),'?','&#147;'),'?','&#148;'),'®','&#174;'),'?','&#153;')
      
,'?','&#151;'),'?','&#183;'),'&#59450;','&#59450;'),'?','&#150;'),'é','&#233;')
      ,'¾','&#190;'),'þ','&#254;'),'o','&#111;'),'?','&#149;'),'â','&#226;')
      ,'ü','&#252;'),'Ü','&#220;'),'?','&#128;'),'?','&#134;'),'x','&#120;')
      
,'¨','&#168;'),'§','&#167;'),'?','&#8211;'),'ã','&#227;'),'&#9473;','&#8212;')
      
,'&#259;','&#259;'),'©','&#169;'),'í','&#237;'),'è','&#232;'),'ç','&#231;')
      ,'á','&#225;'),'?','&#145;'),'ý','&#253;'),'?','&#135;'),'£','&#163;')
      
,'&#8542;','&#8542;'),'¼','&#188;'),'½','&#189;'),'¾','&#190;'),'´','&#180;')
      ,'ú','&#250;'),'ñ','&#241;'),'ð','&#240;'),'ø','&#248;'),'ó','&#243;')
      ,'ê','&#234;'),'à','&#224;')"/>

If I copy the above into some text to use as test data one sees good output as 
a pair of entities like &#146;','&#146; and undesired output which looks bad in 
the html as '&#59450;','&#59450;' a pair of characters with the entity 
converted to a char.

select="$arg,'&#146;','&#146;'),'&#147;','&#147;'),'&#148;','&#148;'),'®','®')
    
,'&#153;','&#153;'),'&#151;','&#151;'),'?','?'),'&#59450;','&#59450;'),'&#150;','&#150;')
    
,'é','é'),'¾','¾'),'þ','þ'),'o','o'),'&#149;','&#149;'),'â','â'),'ü','ü'),'Ü','Ü')
    
,'&#128;','&#128;'),'&#134;','&#134;'),'x','x'),'¨','¨'),'§','§'),'&#151;','&#150;')
    
,'ã','ã'),'?','&#151;'),'&#259;','&#259;'),'©','©'),'í','í'),'è','è'),'ç','ç'),'á','á')
    ,'&#145;','&#145;'),'ý','ý'),'&#135;','&#135;'),'&#146;','&#146;'),'£','£')
    
,'&#147;','&#147;'),'&#148;','&#148;'),'&#149;','&#149;'),'&#8542;','&#8542;'),'¼','¼')
    ,'½','½'),'¾','¾'),'´','´')"

So why is this happening?

Btw if anyone can come teach some software engineering courses next term at the 
university of gambia it would be welcome. I've injured my ankle and won't be 
able to lecture so there is a gap that needs filling. It's fairly easy to work 
remotely here on contracts as long as you bring about 3 laptop batteries with 
you.

Thanks

--
Alex Muir
Instructor | Program Organizer - University Technology Student Work Experience 
Building University of the Gambia http://sites.utg.edu.gm/alex/

Low budget software development benefiting development in the Gambia, West 
Africa Experience of a lifetime, come to Gambia and Join UTSWEB - 
http://sites.utg.edu.gm/utsweb/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>