Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 28th, 2007, 10:30 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default entity conversion

Hi,
I'm writing an xslt file to convert a source xml to a new xml file with diff' tag names.

The source xml has some special entities like "è" etc.
I have a java utility class with a method that converts all "è" type of entities to this type: "#192;"

So i'm calling this method from my xslt file, passing it all text values from the source xml:
<xsl:template match="text()">
     <xsl:value-of select="coca.ext:convertEntity(.)" disable-output-escaping="yes"/>
</xsl:template>

The problem is that the text passed to this method contains "?" instead of the special characters. All entities are transformed somehow into question marks before they get to the java method. So the java utility method cannot match/replace any entity.

I'm running this on unix, so I set the lang env:
setenv LANG "en_US"
setenv LC_CTYPE "en_US.ISO8859-1"

and my xslt has the following:
<?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" omit-xml-declaration="no" encoding="ISO-8859-1"/>
...


I really need to be able to pass the entities to the utility method for conversion. I've spent already 3 days trying to figure it out with no luck.:(

Any help is greatly appreciated.
Thanks,
Orly
  #2 (permalink)  
Old July 29th, 2007, 03:33 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

An XML parser converts entity references like &egrave; to the underlying XML characters. That's its job. So the XSLT code only sees the characters, it doesn't see how they were written.

XSLT is designed to manipulate XML at the logical level, not the lexical level. If you really want low-level control over different representations of the same character, you're better off using a lower-level tool. It's not clear to me why you would care, though - anyone reading the XML should see the different representations as equivalent.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old July 29th, 2007, 12:43 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,
My conversion is not the last one performed on those source files. The next process requires the entities to appear as "#192;" etc.
(It is not my choice).

I still don't understand why my xslt reads/passes the entities as "?".If the XSLT code sees the characters , why is it passing "?" to the output file?

Which lower level tool do you suggest?

Thanks a lot for your help,
Orly


  #4 (permalink)  
Old July 29th, 2007, 03:14 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>The next process requires the entities to appear as "#192;" etc.

One of the benefits of XML is that if your XML is well-formed and your XML parser is conformant, then the parser will be able to process the document. If you're going to use a non-conformant parser to process the XML, then you might as well not bother using XML at all.

>why is it passing "?" to the output file?

You haven't shown any evidence, but my suspicion is that you've got your character encodings in a twist somewhere and you're trying to display a character that's miscoded in some way.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


Similar Threads
Thread Thread Starter Forum Replies Last Post
Entity Conversion vengatatindia Word VBA 0 February 15th, 2008 05:52 AM
character entity into numeric character entity srkumar XSLT 1 November 22nd, 2007 04:53 AM
Entity Question muki XSLT 6 December 5th, 2005 05:28 AM
entity conversion (TidyCOM) Kabe XML 4 September 16th, 2005 07:55 AM
Difference between Entity and Entity type arshad mahmood C++ Programming 0 May 8th, 2004 12:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.