By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,435 Members | 2,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,435 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.