XSL and java.lang.transformer

Discussion in 'XML' started by Angus Parvis, Aug 27, 2004.

  1. Angus Parvis

    Angus Parvis Guest

    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
     
    Angus Parvis, Aug 27, 2004
    #1
    1. Advertising

  2. Angus Parvis

    Derek Harmon Guest

    "Angus Parvis" <> wrote in message news:XdvXc.130746$...
    > 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"
    xmlns:xsl="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"
    xmlns:xsl="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
     
    Derek Harmon, Aug 27, 2004
    #2
    1. Advertising

  3. Angus Parvis

    Angus Parvis Guest

    Derek Harmon wrote:
    > [..]
    > Derek Harmon
    >


    Wooohoo it work's, great haha :) Thank you.
     
    Angus Parvis, Aug 27, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    762
    Esmond Pitt
    Mar 27, 2005
  2. Andreas
    Replies:
    1
    Views:
    947
    Raymond DeCampo
    Sep 4, 2005
  3. Replies:
    1
    Views:
    3,637
    A. Bolmarcich
    May 27, 2005
  4. killy971
    Replies:
    1
    Views:
    703
    Johannes Koch
    Aug 6, 2008
  5. Aéris
    Replies:
    4
    Views:
    1,388
    Arne Vajhøj
    Oct 12, 2011
Loading...

Share This Page