[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: outputting a mixture of escaped and unescaped HTML

Subject: Re: outputting a mixture of escaped and unescaped HTML.
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 21 Jan 2002 21:05:33 -0700 (MST)
unescaped xsl
Dean Missikowski wrote:
> I need to process some xml with attribute values that
> may contain markup text like this:
> 
> <MEMO TEXT="Example:&lt;span
> class=&apos;cs1&apos;&gt;...&lt;/span&gt;$crThis is a
> new line..."/>
> 
> The original data value of the attribute comes from a
> database in which CRLFs were replaced with the string
> $cr.
> 
> I need to transform this into HTML that looks
> something like this:
> 
> <div>Example:&lt;span
> class=&apos;cs1&apos;&gt;...&lt;/span&gt;</br>This is
> a new line...</div>
> 
> The problem I'm having is if I use something like:
> 
> <xsl:template match="MEMO">
>   <xsl:value-of
> select="foo:FormatMultiline(string(@TEXT))" 
> disable-output-escaping="yes"/>
> </xsl:template>
> 
> where foo:FormatMultiline() replaces $cr with </br>.
> 
> However, this results in all the escaped markup to
> become "unescaped" when I want it to remain escaped
> except for the <br/>.

FAQ, although you're not really understanding what escaped text means.
Regardless, here's your solution.

  <xsl:template match="MEMO">
    <div>
      <xsl:call-template name="lf2br">
        <xsl:with-param name="StringToTransform" select="@TEXT"/>
      </xsl:call-template>
    </div>
  </xsl:template>

  <xsl:template name="lf2br">
    <xsl:param name="StringToTransform"/>
    <xsl:choose>
      <xsl:when test="contains($StringToTransform,'&#xA;')">
        <xsl:value-of select="substring-before($StringToTransform,'&#xA;')"/>
        <br/>
        <xsl:call-template name="lf2br">
          <xsl:with-param name="StringToTransform">
            <xsl:value-of select="substring-after($StringToTransform,'&#xA;')"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$StringToTransform"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

   - Mike
____________________________________________________________________________
  mike j. brown, fourthought.com  |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  personal: http://hyperreal.org/~mike/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.