#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    Long Island, NY
    Posts
    3
    Rep Power
    0

    <br/> tag in XSL variable


    I'm trying to get an HTML <br> tag, embedded into an XSL variable and I'm not sure that it's possible.

    In short, I have stylesheet1.xsl which performs a specific function. stylesheet1.xsl includes Language.xsl. Within Language.xsl are all of the text strings that stylesheet1 uses (the reason for this is that there are 45+ stylesheets, however only one needs to be modified to change the language of the entire package.)

    Within Language.xsl, I would like to define a variable lit_QuantityReceived. Such as:

    <xsl:variable name="lit_QuantityReceived">Quantity Received</xsl:variable>

    However, I would like to insert an HTML break in between the two words, so my result from inserting "$lit_QuantityReceived" in HTML would be:

    Quantity<br/>Received

    I've tried quite a few options that don't work. &lt; doesn't work because the browser doesn't intepret that as the beginning of a tag, escaping a linefeed actually puts a line break in the HTML instead of a <br> tag, and I can't seem to find a single way to get a < or > symbol into my variable definition.

    I've even referenced the xhtml DTD:

    <br xmlns:html="http://www.w3.org/1999/xhtml" />

    which *does* work when you use it directly in a .xsl, but not when you embed it within the variable as I'm trying to do.

    Is this possible?

    Thanks in advance.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Posts
    11
    Rep Power
    0

    this may help


    I am not sure if you can store Document nodes as part of a value, so the next best thing is to apply a separate stylesheet template that will convert characters (in this case a space) to line breaks (<br/>)

    heres an example of swapping a space for a break.

    <xsl:template name="break">
    <xslaram name="text" select="."/>
    <xsl:choose>
    <xsl:when test="contains($text, ' ')">
    <xsl:value-of select="substring-before($text, ' ')"/>
    <br/>
    <xsl:call-template name="break">
    <xsl:with-param name="text" select="substring-after($text,' ')"/>
    </xsl:call-template>
    </xsl:when>
    <xsltherwise>
    <xsl:value-of select="$text"/>
    </xsltherwise>
    </xsl:choose>
    </xsl:template>

    to apply this to a value just do this:

    <xsl:call-template name="break">
    <xsl:with-param name="text" select="$yourVariable"/>
    </xsl:call-template>
  4. #3
  5. No Profile Picture
    Joonior Meember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Barre, VT, USA, Earth
    Posts
    11
    Rep Power
    0
    Can you discuss the positive and negative effects of smileys in XML code?

    Just kidding

    Zach
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    Long Island, NY
    Posts
    3
    Rep Power
    0

    Talking Unpredictable Results


    Thanks for the humor Zach.

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Belarus
    Posts
    30
    Rep Power
    13
    hi high-1

    I think you should try this

    Code:
    variable definition :
    <xsl:variable name="lit_QuantityReceived"> Quantity &lt;br&gt;Received</xsl:variable>
    
    
    output variable :
    
    <xsl:value-of disable-output-escaping="yes" select="$lit_QuantityReceived"/>

IMN logo majestic logo threadwatch logo seochat tools logo