aspose file tools*
The moose likes XML and Related Technologies and the fly likes nbsp in .xsl? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "nbsp in .xsl?" Watch "nbsp in .xsl?" New topic
Author

nbsp in .xsl?

Nils Persson
Greenhorn

Joined: May 25, 2001
Posts: 21
Again...
What do I do if I want to have the ' ' in my .xsl file? When I run the SimpleTransform example and have the " " in my .xsl file I get an error: javax.xml.transform.TransformerConfigurationException: The entity 'nbsp' was referenced, but not declared.
How do I write so it doesn't think it's an entity?
Problem 2: I want to have the 'nowrap' in my HTML tag <td> but the transformer can't handle it.
/Nils
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
you need to escape the '&' using '&amp;' (ie, for each non-breaking space you want in the output, use '&amp;nbsp;')
[This message has been edited by Frank Carver (edited June 08, 2001).]


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
As for the nowrap attribute, there should be no problem with generating it. Can you give a little more information about what you are trying, and what actually happens?
Nils Persson
Greenhorn

Joined: May 25, 2001
Posts: 21
When I put the nowrap in I get this error:
Attribute name "td" must be followed by the '=' character
The code:
<td class="txt" valign="top" align="right" NOWRAP>
When I take the nowrap away it works fine.
If I change the & nbsp to & amp;nbsp; it just writes it to the screen.
/Nils
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Ah, I see the problem with the nowrap. It's not valid XML. Have you tried adding a dummy value for the nowrap attribute: nowrap='' ?
As for the nbsp, what are you using to process your XSL, and how are you sending the result to the browser? I've generated entity sequences like this before with no trouble, so I guess you are doing something a bit different from my experience.
Nils Persson
Greenhorn

Joined: May 25, 2001
Posts: 21
Thanks.
Ok, I try nowrap= thing...
I use the SimpleTransform example from IBM LotusXSL. That takes two files .xsl and .xml and a third output file .html.
From my site I just include the .html file.
Do I have to have a .dtd file to declare the nbsp?
/Nils
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
XSL stylesheet is an XML document itself, so it is perfectly possible to have DTD in it:
<?xml version='1.0'?>
<!DOCTYPE stylesheet [
<!ENTITY nbsp "�" >
]>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
...

Then you can simply type &nbsp; in your XSLT. I used the construction above and it works fine
[This message has been edited by Mapraputa Is (edited June 08, 2001).]


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Interesting. NOWRAP thing is rather mysterious. Seems to be the only HTML attribute breaking well-formedness. But it is how TD tag is defined:
<TD LANG="..." DIR=ltr|rtl ID="..." CLASS="..." AXIS="..." AXES="..." NOWRAP ROWSPAN=value COLSPAN=value ALIGN=left|right|center|justify|char|decimal CHAR="..." CHAROFF="..." DP="..." VALIGN=top|middle|bottom|baseline WIDTH=value BGCOLOR="...">characters...</TD>
I wonder what was the reason to make NOWRAP a syntactic exception?
Also <P> tag is defined as
<P ... WRAP=on|off NOWRAP ...>

I hope Frank�s variant will work. If not, you will need to bury yourself into <xsl:text> mess
If you need simply output TD tag with NOWRAP word, regardless of XML data, you can go like this:
<xsl:text disable-output-escaping="yes">
&lt;td class="txt" valign="top" align="right" NOWRAP>
</xsl:text>

If you need to output some part of the TD tag based on XML data, say, you need to read the value for your class attribute, then it is a bit more complicated.
Assuming the value is in <properElement properAttribute=�...�>, we break the target expression into three parts:

1. <xsl:text disable-output-escaping="yes">
&lt;td class="</xsl:text>
2. <xsl:value-of select="properElement/@properAttribute"/>
3. <xsl:text disable-output-escaping="yes">" valign="top" align="right" NOWRAP>
</xsl:text>


[This message has been edited by Mapraputa Is (edited June 08, 2001).]
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Yes! Frank�s advice will work in XHTML variant:
"The HTML to XHTML Headache -- What Needs to Change:
XML does not allow attribute minimization.
Stand-alone attributes must be expanded (eg. <td nowrap>cell</td> becomes <td nowrap="nowrap">cell</td> )
(URL: http://www.zdnet.com/devhead/resources/tag_library/history/xhtml.html)
tom_2000
Greenhorn

Joined: Jun 05, 2001
Posts: 7
sorry, but have u tried   for space.
and nowrap="true" ?
tom_2000
Greenhorn

Joined: Jun 05, 2001
Posts: 7
i guess the ' ' from the last post worked, it didnt' show!
(leave out the single quotes in yr code)
tom_2000
Greenhorn

Joined: Jun 05, 2001
Posts: 7
ok, so sorry, last try:
i typed it &.#.160.;
leave out the period in your code.
aiooua
Greenhorn

Joined: Apr 08, 2001
Posts: 12
Dear...,
I don't know whether u still have the problem with the space. Still I have something that works.( I have seen it work. )
<xsl:text disable-output-escaping="yes">& amp;nbsp;</xsl:text> whereever you wish to use �.
Using an entity that puts in ' ' in a document is as good as putting a space. I guess so! please correct me if I am wrong.
AJD.
------------------
-AJD.
[This message has been edited by Aldrin Dsouza (edited July 09, 2001).]
[This message has been edited by Aldrin Dsouza (edited July 09, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nbsp in .xsl?