Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Dingley 1431 posts 3332 karma points c-trib
    Jan 11, 2010 @ 15:45
    Simon Dingley
    0

    Whitespace Issues

    I am no XSLT pro so any advice on this would be appreciated. See the following XSLT:

                                    <xsl:attribute name="id">
                                        mnu<xsl:call-template name="replace-string">
                                            <xsl:with-param name="text">
                                                <xsl:value-of select="@id" />
                                            </xsl:with-param>
                                            <xsl:with-param name="from" select="' '"/>
                                            <xsl:with-param name="to" select="'-'"/>
                                        </xsl:call-template>
                                    </xsl:attribute>

    Nicely formatted in the XSLT file but the final source code output has problems caused by the whitespace e.g.

    <li id="&#xD;&#xA;                                    mnu4079" class="&#xD;&#xA;                            nav1">

    Is there anything I can do to cause the XSLT stylesheet to ignore the whitespace so that I can maintain the formatting in the XSLT file whilst still getting the HTML output I require?

  • dandrayne 1138 posts 2262 karma points
    Jan 11, 2010 @ 15:49
    dandrayne
    1

    This is a handy article I had saved somewhere -> http://www.ibm.com/developerworks/xml/library/x-tipwhitesp.html

    there's strip-whitespace and preserve-whitespace ellments, and this can also be controlled to some degree by using xsl:text.

    Hope this sets you off in the right direction!  It's a pain to chose between readable input and readable/functional output.

    Dan

    <xsl:attribute name="id">
    <xsl:text>mnu</xsl:text>
    <xsl:call-template name="replace-string">
    ...snip...
  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jan 11, 2010 @ 15:50
    Sebastiaan Janssen
    1

    Yes, instead of "mnu<xsl:...", do it like this (surround strings with the xsl:text element):

    <xsl:attribute name="id">
        <xsl:text>mnu</xsl:text>
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text">
                <xsl:value-of select="@id" />
            </xsl:with-param>
            <xsl:with-param name="from" select="' '"/>
            <xsl:with-param name="to" select="'-'"/>
        </xsl:call-template>
    </xsl:attribute>
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies