[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Some entities output as entities and others as cha

Subject: RE: Some entities output as entities and others as chars not looking good in the html.. why?
From: Scott Trenda <Scott.Trenda@xxxxxxxx>
Date: Tue, 13 Dec 2011 13:27:48 -0500
RE:  Some entities output as entities and others as cha
Alex,

This is probably happening because your output encoding is set to something too inclusive for your destination output. The XSLT processor sees &#220;, 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.g.muir@xxxxxxxxx] 
Sent: Tuesday, December 13, 2011 12:03 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  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;'),'i','&#233;')
      ,'>','&#190;'),'~','&#254;'),'o','&#111;'),'','&#149;'),'b','&#226;')
      ,'|','&#252;'),'\','&#220;'),'','&#128;'),'','&#134;'),'x','&#120;')
      ,'(','&#168;'),''','&#167;'),'','&#8211;'),'c','&#227;'),'&#9473;','&#8212;')
      ,'&#259;','&#259;'),')','&#169;'),'m','&#237;'),'h','&#232;'),'g','&#231;')
      ,'a','&#225;'),'','&#145;'),'}','&#253;'),'','&#135;'),'#','&#163;')
      ,'&#8542;','&#8542;'),'<','&#188;'),'=','&#189;'),'>','&#190;'),'4','&#180;')
      ,'z','&#250;'),'q','&#241;'),'p','&#240;'),'x','&#248;'),'s','&#243;')
      ,'j','&#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;')
    ,'i','i'),'>','>'),'~','~'),'o','o'),'&#149;','&#149;'),'b','b'),'|','|'),'\','\')
    ,'&#128;','&#128;'),'&#134;','&#134;'),'x','x'),'(','('),''','''),'&#151;','&#150;')
    ,'c','c'),'','&#151;'),'&#259;','&#259;'),')',')'),'m','m'),'h','h'),'g','g'),'a','a')
    ,'&#145;','&#145;'),'}','}'),'&#135;','&#135;'),'&#146;','&#146;'),'#','#')
    ,'&#147;','&#147;'),'&#148;','&#148;'),'&#149;','&#149;'),'&#8542;','&#8542;'),'<','<')
    ,'=','='),'>','>'),'4','4')"

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/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.