Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL and java.lang.transformer

Reply
Thread Tools

XSL and java.lang.transformer

 
 
Angus Parvis
Guest
Posts: n/a
 
      08-27-2004
Hi,

I've already posted this in comp.lang.java.programmer, but it doesn't
seem like the ppl there can help. I hope you guys here know more about
it, altough my question is more java than xml related

Here's the problem:

I have a XSL Stylesheet. Using the java.xml.transform.Transformer I
transform XML to HTML. My XSL contains spaces and entities like
"©".

This code for example contains a space between text1 and text2:

<xsl:value-of select="$text1"/> <xsl:value-of select="$text2"/>

But after transformation the space is gone! If there was any space
character in text1 or text2, it's still there, but the space between
those two disappered. What am I doing wrong? I don't want my text to
stick together ..

The second this is a problem with entities. Whenever I use an entity
like "&copy" or "&nbsp;", java.xml.transform.Transformer tells me, that
this entity is unknown and refuses work until i remove the entity from
the HTML code. What's the problem here? How can I use HTML entities
without troubles?

Thanks for your help,

Angus
 
Reply With Quote
 
 
 
 
Derek Harmon
Guest
Posts: n/a
 
      08-27-2004
"Angus Parvis" <(E-Mail Removed)> wrote in message news:XdvXc.130746$(E-Mail Removed)...
> seem like the ppl there can help. I hope you guys here know more about
> it, altough my question is more java than xml related


It may surprise you to learn your question(s) are entirely
XML-related.

> Here's the problem:

: :
> This code for example contains a space between text1 and text2:
>
> <xsl:value-of select="$text1"/> <xsl:value-of select="$text2"/>
>
> But after transformation the space is gone!


Most whitespace between elements in the stylesheet is insignificant,
unless you direct otherwise. Two options:

1. Add xml:space="preserve" to the xsl:stylesheet element of your
stylesheet so that it resembles the following example:

<xsl:stylesheet
version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xml:space="preserve" >

This may preserve more space than you want. Whitespace in
in your stylesheet is more-often than not present to aid clarity
and readability, and normally this is undesirable in the output.

2. Use an <xsl:text> element. Whitespace in an <xsl:text> element
is significant. Here is an example of preserving 3 spaces between
two book titles:

<xsl:value-of select="//book[1]/@title" /><xsl:text> </xsl:text><xsl:value-of select="//book[2]/@title" />

: :
> The second this is a problem with entities. Whenever I use an entity
> like "&copy" or "&nbsp;", java.xml.transform.Transformer tells me, that
> this entity is unknown and refuses work until i remove the entity


These entities are unknown to the stylesheet. Tell the stylesheet
what their definitions are in the DTD internal subset of your style-
sheet, as in the following example:

<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
<!ENTITY copy "©">
]>
<xsl:stylesheet
version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform" >

Alternately, you can use the character entity reference,  ,
directly within the content of the stylesheet and dispense with the
DTD internal subset altogether.


Derek Harmon


 
Reply With Quote
 
 
 
 
Angus Parvis
Guest
Posts: n/a
 
      08-27-2004
Derek Harmon wrote:
> [..]
> Derek Harmon
>


Wooohoo it work's, great haha Thank you.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
xsl:import and xsl:apply_import David Carlisle XML 5 12-16-2004 02:44 PM
XSLT question related to <xsl:template> and <xsl:apply-templates> Vijay singh XML 1 11-04-2004 03:42 PM
Difference between xsl:param and xsl:variable? Karsten Weinert XML 3 07-05-2004 04:58 PM
Three question which is not yet answered clearly and correct so far !! challenging question in xsl and also in xsl fo Philip Meyer XML 0 11-30-2003 04:42 PM



Advertisments