XSL: Whitespace Problem With HTML Output

Discussion in 'XML' started by josh.asbury@gmail.com, Jan 28, 2005.

  1. Guest

    I am having some major issues with whitespace in my XSL stylesheets.
    We recently upgraded our servlet-based application to JDK 1.4, and this
    has forced the issue of my finally upgrading to Xalan-Java 2. The
    earlier version of Xalan was much more forgiving in regards to
    whitespace in our .xsl files, and now I am learning all about
    <xsl:text> and <xsl:strip-space>.

    I've come across something with HTML buttons, though, that I can't find
    a way around.

    Our XSL looks like this:
    <input type="button" name="save" id="save"
    onClick="thisValidate()"> <xsl:attribute
    name="value">select</xsl:attribute>
    </input>
    <span style="width:5"/>
    <input type="button" name="cancel" id="cancel" value="cancel">
    <xsl:attribute name="onClick">window.navigate('<xsl:value-of
    select="$parentPage"/>?catid=<xsl:value-of
    select="$categoryId"/>')</xsl:attribute> </input>

    Which outputs to HTML exactly like this:
    <INPUT onClick="thisValidate()" id="save" name="save" type="button"
    value="select"><span style="width:5"></span><input value="cancel"
    id="cancel" name="cancel" type="button"
    onClick="window.navigate('AddLocalServicesByCategory


    ?catid=204194')">
    ---------------------------------------------

    I'm stumped. I've put <xsl:text/> in the window.navigate section.
    I've put <xsl:strip-space elements="*"/> in the stylesheet ( which, I
    think, shouldn't impact this behavior ).

    Any insight or ideas on this would be greatly appreciated. I've got a
    ton of stylesheets behaving like this and need to have a solid
    go-forward plan in order to make this upgrade a success.

    Thanks!
    Josh
     
    , Jan 28, 2005
    #1
    1. Advertising

  2. Joris Gillis Guest

    Tempore 22:36:35, die Friday 28 January 2005 AD, hinc in foro {comp.text.xml} scripsit <>:

    > Our XSL looks like this:
    > <input type="button" name="save" id="save"
    > onClick="thisValidate()"> <xsl:attribute
    > name="value">select</xsl:attribute>
    > </input>
    > <span style="width:5"/>
    > <input type="button" name="cancel" id="cancel" value="cancel">
    > <xsl:attribute name="onClick">window.navigate('<xsl:value-of
    > select="$parentPage"/>?catid=<xsl:value-of
    > select="$categoryId"/>')</xsl:attribute> </input>
    >
    > Which outputs to HTML exactly like this:
    > <INPUT onClick="thisValidate()" id="save" name="save" type="button"
    > value="select"><span style="width:5"></span><input value="cancel"
    > id="cancel" name="cancel" type="button"
    > onClick="window.navigate('AddLocalServicesByCategory
    >
    >
    > ?catid=204194')">
    > ---------------------------------------------
    >
    > I'm stumped. I've put <xsl:text/> in the window.navigate section.
    > I've put <xsl:strip-space elements="*"/> in the stylesheet ( which, I
    > think, shouldn't impact this behavior ).

    well, in fact it does not. The 'strip-space' element tells the XSLT processor to omit text nodes that contain nothing but whitespaces.

    It seems the problem lies with the 'parentPage' variable; it contains linebreaks. You can trim the whitespaces with the 'normalize-space()':
    <xsl:value-of select="normalize-space($parentPage)"/>

    Better would be to prohibit the linebreaks from being added at all when you create the variable.

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    "Et ipsa scientia potestas est" - Francis Bacon , Meditationes sacrae
     
    Joris Gillis, Jan 29, 2005
    #2
    1. Advertising

  3. Josh Guest

    That did it. Thanks!!
     
    Josh, Jan 31, 2005
    #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. Oli Filth
    Replies:
    9
    Views:
    3,368
    Uncle Pirate
    Jan 17, 2005
  2. Replies:
    1
    Views:
    465
    David Carlisle
    Jul 18, 2005
  3. Simon Brooke
    Replies:
    6
    Views:
    596
    Joseph Kesselman
    Oct 24, 2007
  4. Replies:
    10
    Views:
    803
    Eric Brunel
    Dec 16, 2008
  5. MRAB
    Replies:
    3
    Views:
    409
Loading...

Share This Page