473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[XSL] How do i get & #160; to pass through?

I have a basic understanding of this, so forgive me if I am overly
simplistic in my explanation of my problem..

I am trying to get a Java/Xalan transform to pass through a numeric
character reference (i.e.  ) and it seems to be converting the
character to its UNICODE representation.

Take this source XML document:

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
some space separated text
</sourcexml>

And this stylesheet:

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|*|text()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

I am trying to get it to regurgitate the original document, with the
 's intact. Instead I am getting bizarre characters (copied from
windows CMD window):

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
someáspaceáseparatedátext
</sourcexml>

Here is how I am doing my transform (java code):

SAXSource in = new SAXSource(new InputSource(new
StringReader(this.xmlDocument)));

// build the out result
StringWriter writer = new StringWriter();
StreamResult out = new StreamResult(writer);

// build the transformer
SAXSource stylesheetIn = new SAXSource(new InputSource(new
StringReader(this.xslStylesheet)));
Transformer transformer =
TransformerFactory.newInstance().newTransformer(st ylesheetIn);

// transform the string.
transformer.transform(in,out);

// return the transformation result.
return writer.toString();

Any ideas? Any help would be very appreciated. Thanks :)

Jul 20 '05 #1
9 8511
Collin VanDyck <se*****************@hannonhill.com> scribbled the following
on comp.lang.java.programmer:
I have a basic understanding of this, so forgive me if I am overly
simplistic in my explanation of my problem.. I am trying to get a Java/Xalan transform to pass through a numeric
character reference (i.e.  ) and it seems to be converting the
character to its UNICODE representation. Take this source XML document: <?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
some space separated text
</sourcexml>


I'm not sure if this is what you want, but one way to get the literal
string " " to appear in the output is to write it as:
"&amp;#160;" in the source code. To get *that* to appear, write it as
"&amp;amp;#160;" and so on. Of course I could be trying to solve the
wrong problem here.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"This isn't right. This isn't even wrong."
- Wolfgang Pauli
Jul 20 '05 #2
Hi...

Thanks for the reply, but I tried that, and it produced:

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
some&amp;amp;#160;space&amp;amp;#160;separated&amp ;amp;#160;text
</sourcexml>

where what I am aiming to get is:

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
some space separated text
</sourcexml>

thanks,

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bp*********@oravannahka.helsinki.fi...
Collin VanDyck <se*****************@hannonhill.com> scribbled the following on comp.lang.java.programmer:
I have a basic understanding of this, so forgive me if I am overly
simplistic in my explanation of my problem..

I am trying to get a Java/Xalan transform to pass through a numeric
character reference (i.e.  ) and it seems to be converting the
character to its UNICODE representation.

Take this source XML document:

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
some space separated text
</sourcexml>


I'm not sure if this is what you want, but one way to get the literal
string " " to appear in the output is to write it as:
"&amp;#160;" in the source code. To get *that* to appear, write it as
"&amp;amp;#160;" and so on. Of course I could be trying to solve the
wrong problem here.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"This isn't right. This isn't even wrong."
- Wolfgang Pauli


Jul 20 '05 #3
I thought these character entity-references need 4 digits if you want to
specify a decimal value
(character-code 160 as the &nbsp; in HTML) (and not 3, as in your example).

Try

 

(instead of  )

-- Anton.

"Collin VanDyck" <se*****************@hannonhill.com> wrote in message
news:8a******************************@news.teranew s.com...
I have a basic understanding of this, so forgive me if I am overly
simplistic in my explanation of my problem..

I am trying to get a Java/Xalan transform to pass through a numeric
character reference (i.e.  ) and it seems to be converting the
character to its UNICODE representation.

Take this source XML document:

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
some space separated text
</sourcexml>

And this stylesheet:

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|*|text()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

I am trying to get it to regurgitate the original document, with the
 's intact. Instead I am getting bizarre characters (copied from
windows CMD window):

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
someáspaceáseparatedátext
</sourcexml>

Here is how I am doing my transform (java code):

SAXSource in = new SAXSource(new InputSource(new
StringReader(this.xmlDocument)));

// build the out result
StringWriter writer = new StringWriter();
StreamResult out = new StreamResult(writer);

// build the transformer
SAXSource stylesheetIn = new SAXSource(new InputSource(new
StringReader(this.xslStylesheet)));
Transformer transformer =
TransformerFactory.newInstance().newTransformer(st ylesheetIn);

// transform the string.
transformer.transform(in,out);

// return the transformation result.
return writer.toString();

Any ideas? Any help would be very appreciated. Thanks :)

Jul 20 '05 #4
Thanks, but same result. I ended up deciding to pass everything through an
xml encoder-decoder that would do a regex replaceAll on

&#([0-9+);

to

[unicode]$1[/unicode]

And after the transform was done, reverse it back into the character
reference syntax.
"Anton Spaans" <aspaans at(noSPAM) smarttime dot(noSPAM) com> wrote in
message news:86********************@speakeasy.net...
I thought these character entity-references need 4 digits if you want to
specify a decimal value
(character-code 160 as the &nbsp; in HTML) (and not 3, as in your example).
Try

 

(instead of  )

-- Anton.

"Collin VanDyck" <se*****************@hannonhill.com> wrote in message
news:8a******************************@news.teranew s.com...
I have a basic understanding of this, so forgive me if I am overly
simplistic in my explanation of my problem..

I am trying to get a Java/Xalan transform to pass through a numeric
character reference (i.e.  ) and it seems to be converting the
character to its UNICODE representation.

Take this source XML document:

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
some space separated text
</sourcexml>

And this stylesheet:

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|*|text()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

I am trying to get it to regurgitate the original document, with the
 's intact. Instead I am getting bizarre characters (copied from
windows CMD window):

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
someáspaceáseparatedátext
</sourcexml>

Here is how I am doing my transform (java code):

SAXSource in = new SAXSource(new InputSource(new
StringReader(this.xmlDocument)));

// build the out result
StringWriter writer = new StringWriter();
StreamResult out = new StreamResult(writer);

// build the transformer
SAXSource stylesheetIn = new SAXSource(new InputSource(new
StringReader(this.xslStylesheet)));
Transformer transformer =
TransformerFactory.newInstance().newTransformer(st ylesheetIn);

// transform the string.
transformer.transform(in,out);

// return the transformation result.
return writer.toString();

Any ideas? Any help would be very appreciated. Thanks :)



Jul 20 '05 #5
"Collin VanDyck" <se*****************@hannonhill.com> wrote in message
news:8a******************************@news.teranew s.com...
I am trying to get a Java/Xalan transform to pass through a numeric
character reference (i.e.  ) and it seems to be converting the
character to its UNICODE representation.


Probably UTF-8 encoded. Try specifying the encoding to generate in
your xsl:output element. Iso-8859-1 should do what you want.

Groetjes,
Maarten Wiltink
Jul 20 '05 #6
Collin VanDyck wrote:
I have a basic understanding of this, so forgive me if I am overly
simplistic in my explanation of my problem..

I am trying to get a Java/Xalan transform to pass through a numeric
character reference (i.e.  ) and it seems to be converting the
character to its UNICODE representation.

Take this source XML document:

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
some space separated text
</sourcexml>

And this stylesheet:

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|*|text()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

I am trying to get it to regurgitate the original document, with the
 's intact. Instead I am getting bizarre characters (copied from
windows CMD window):


That's how the XPath data model works - the information about whether a
character originally was entered as a numerical entitity isn't available
- so there's no chance to preserve that bit of information using XSLT.

(amazing how many wrong suggestions were made :-)

Julian
Jul 20 '05 #7
Collin VanDyck wrote:
I have a basic understanding of this, so forgive me if I am overly
simplistic in my explanation of my problem..

I am trying to get a Java/Xalan transform to pass through a numeric
character reference (i.e.  ) and it seems to be converting the
character to its UNICODE representation.

Take this source XML document:

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
some space separated text
</sourcexml>

And this stylesheet:

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|*|text()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

I am trying to get it to regurgitate the original document, with the
 's intact. Instead I am getting bizarre characters (copied from
windows CMD window):

<?xml version="1.0" encoding="UTF-8"?>
<sourcexml>
someáspaceáseparatedátext
</sourcexml>


This an understandable behaviour:

* The   is parsed by the XML parser, and is considered being a
NO-BREAK SPACE Unicode character. See here:
<http://www.unicode.org/charts/PDF/U0080.pdf>, character 0xA0.

* The XML is parsed with the XSL, and the NO-BREAK SPACE Unicode
character is kept unchanged in the result XML document.

* The output document is encoded as ISO-8859-1 (Latin 1) for some reason
(this is the default character encoding on many platforms), instead of
UTF-8, and in ISO-8859-1, the NO-BREAK SPACE character is encoded as a
single 0xA0 byte.

* When the CMD window tries to display the character, it understands the
XML document as being encoded in the CP437 character set (the *very* old
DOS character set, for compatibility). It gets the 0xA0 byte, and in
CP437 the 0xA0 byte represents the LATIN SMALL LETTER A WITH ACUTE
Unicode character, which is what you see. See here:
<http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/PC/CP437.TXT>
Of course in UTF-8 the output would have been the folowing bytes:
some space separated text (Latin 1 bytes)
which in CMD would be displayed as something I can't type here, because
it invloves 0xc2 'BOX DRAWINGS LIGHT DOWN AND HORIZONTAL' characters.
It would probably have looked like this:
some|áspace|áseparated|átext

--
Laurent

Jul 20 '05 #8
"Maarten Wiltink" <ma*****@kittensandcats.net> wrote in message
news:3f***********************@news.xs4all.nl...
"Collin VanDyck" <se*****************@hannonhill.com> wrote in message
news:8a******************************@news.teranew s.com...
I am trying to get a Java/Xalan transform to pass through a numeric
character reference (i.e.  ) and it seems to be converting the
character to its UNICODE representation.


Probably UTF-8 encoded. Try specifying the encoding to generate in
your xsl:output element. Iso-8859-1 should do what you want.


On second thoughts, it shouldn't. Since U+00a0 is a valid character
in iso-8859-1, it will be output verbatim. Asking for output in
(7-bits) us-ascii should cause the processor to produce a character
entity.

Groetjes,
Maarten Wiltink
Jul 20 '05 #9
In article <8a******************************@news.teranews.co m>,
Collin VanDyck <se*****************@hannonhill.com> wrote:
I am trying to get a Java/Xalan transform to pass through a numeric
character reference (i.e.  ) and it seems to be converting the
character to its UNICODE representation.


This is normal. *Why* do you want to have it output as  ? It
shouldn't make any difference to the programs that use the output, if
they read it as XML.

If you want it for readability, you could specify that the output
encoding should be ascii.

-- Richard

--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: wharfprada | last post by:
this one is very puzzling to me. everytime i add   to my xsl file it is displayed as ? mark. I changed my encoding from UTF-8 to ISO-8859-1 and was still gettin the same problem. any idea ...
2
by: Robert | last post by:
when using the following function to create a pass through query is there a way to set the query property, "Returns Rows" to no. The default is yes. Since we are planning to create the pass...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
3
by: Zlatko Matić | last post by:
Hello. I'm wondernig what is happennig whith saved pass-through queries nested in regular JET query if regular JET query just filtrates result by start/end date...Does pass-through query first...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
3
by: ILCSP | last post by:
Hello, I'm fairly new to the concept of running action pass through queries (insert, update, etc.) from Access 2000. I have a SQL Server 2000 database and I'm using a Access 2K database as my...
1
by: Greg Strong | last post by:
Hello All, Why would brackets be added to the SQL of a pass through query to Oracle? If I paste the debug print of the SQL statement into SQLPlus of Oracle's XE edition it works, and does NOT...
5
by: marshmallowww | last post by:
I have an Access 2000 mde application which uses ADO and pass through queries to communicate with SQL Server 7, 2000 or 2005. Some of my customers, especially those with SQL Server 2005, have had...
13
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.