Solved

Disable output escaping

Posted on 2007-11-27
1
900 Views
Last Modified: 2013-11-18
Hello Expert [Gertone],

I have an same query which i asked before about disable output escaping.
In output htmls i have found that at some places it is retaining &lt; as input xml also contains &lt; but at few places it is not retaing and changed it to '<'...I have also unit test and check the unit test output is proper.

Please find below test.xml and test.xsl for the same...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:xalan="http://xml.apache.org/xalan">
      <xsl:variable name="hiddenProductName" select="'flex'"/>
      <!--xsl:character-map name="disable">
            <xsl:output-character character="&amp;" string="&amp;"/>
            <xsl:output-character character="&lt;" string="&lt;"/>
            <xsl:output-character character="&gt;" string="&gt;"/>
      </xsl:character-map-->
      <xsl:template match="/">
            <xsl:apply-templates/>
      </xsl:template>
      <xsl:template match="p">
            <xsl:variable name="product" select="./@product|./@class | ./@outputclass"/>
            <xsl:if test="string-length($product)=0 or not($product=concat($hiddenProductName,'only'))">
                  <xsl:value-of disable-output-escaping="yes" select="'&lt;p&gt;'"/>
                  <xsl:call-template name="processTags"/>
                  <xsl:value-of disable-output-escaping="yes" select="'&lt;/p&gt;'"/>
            </xsl:if>
      </xsl:template>
      <xsl:template name="processTags">
            <xsl:param name="input"/>
            <xsl:param name="addParagraphTags" select="false()"/>
            <xsl:param name="createLinkFromRootContext" select="false()"/>
            <xsl:variable name="matchHTML" select="./adobetable |  ./ol |  ./p | ./codeblock |  ./ul |  ./b |  ./adobeimage | ./ph |  ./codeph | ./bold | ./strong |  ./em |  ./i |  ./xref | ./pre | ./text() | ./li| ./sup"/>
            <xsl:for-each select="$matchHTML">
                  <xsl:if test="self::text()">
                        <xsl:if test="$addParagraphTags">
                              <xsl:if test="position()=1">
                                    <xsl:value-of disable-output-escaping="yes" select="'&lt;p&gt;'"/>
                              </xsl:if>
                        </xsl:if>
                        <xsl:variable name="text">
                              <xsl:call-template name="search-and-replace">
                                    <xsl:with-param name="search-string" select="'~~'"/>
                                    <xsl:with-param name="replace-string" select="'*'"/>
                                    <xsl:with-param name="input" select="."/>
                              </xsl:call-template>
                        </xsl:variable>

                        <xsl:value-of select="$text" disable-output-escaping="no"/>

                        <xsl:if test="$addParagraphTags">
                              <xsl:if test="position()=last()">
                                    <xsl:value-of disable-output-escaping="yes" select="'&lt;/p&gt;'"/>
                              </xsl:if>
                        </xsl:if>
                  </xsl:if>
                  <xsl:if test="self::codeblock">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::ol | self::ul">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::li">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::p">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::b | self::bold | self::strong">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::adobetable">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::adobeimage">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::ph">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::sup">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::em | self::i">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::codeph">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
                  <xsl:if test="self::xref">
                        <xsl:apply-templates select=".">
                              <xsl:with-param name="createLinkFromRootContext" select="$createLinkFromRootContext"/>
                        </xsl:apply-templates>
                  </xsl:if>
                  <xsl:if test="self::pre">
                        <xsl:apply-templates select="."/>
                  </xsl:if>
            </xsl:for-each>
      </xsl:template>
      <xsl:template match="pre">
            <xsl:variable name="product" select="@product| @class | @outputclass"/>
            <xsl:if test="string-length($product)=0 or not($product=concat($hiddenProductName,'only'))">
                  <xsl:value-of disable-output-escaping="yes" select="'&lt;pre&gt;'"/>
                  <!-- Bug#:1583029 -->
                  <xsl:variable name="replacelt">
                        <xsl:call-template name="search-and-replace">
                              <xsl:with-param name="search-string" select="'&lt;'"/>
                              <xsl:with-param name="replace-string" select="'&amp;lt;'"/>
                              <xsl:with-param name="input" select="."/>
                        </xsl:call-template>
                  </xsl:variable>
                  <xsl:variable name="texts">
                        <xsl:call-template name="search-and-replace">
                              <xsl:with-param name="search-string" select="'&gt;'"/>
                              <xsl:with-param name="replace-string" select="'&amp;gt;'"/>
                              <xsl:with-param name="input" select="$replacelt"/>
                        </xsl:call-template>
                  </xsl:variable>
                  <xsl:call-template name="processTags">
                        <xsl:with-param name="input" select="$texts"/>
                  </xsl:call-template>
                  <xsl:value-of disable-output-escaping="yes" select="'&lt;/pre&gt;'"/>
            </xsl:if>
      </xsl:template>
      <xsl:template name="search-and-replace">
            <xsl:param name="input"/>
            <xsl:param name="search-string"/>
            <xsl:param name="replace-string"/>
            <xsl:choose>
                  <xsl:when test="$search-string and contains($input,$search-string)">
                        <xsl:value-of select="substring-before($input,$search-string)"/>
                        <xsl:value-of select="$replace-string" disable-output-escaping="no"/>
                        <xsl:call-template name="search-and-replace">
                              <xsl:with-param name="input" select="substring-after($input,$search-string)"/>
                              <xsl:with-param name="search-string" select="$search-string"/>
                              <xsl:with-param name="replace-string" select="$replace-string"/>
                        </xsl:call-template>
                  </xsl:when>
                  <xsl:otherwise>
                        <xsl:value-of select="$input" disable-output-escaping="no"/>
                  </xsl:otherwise>
            </xsl:choose>
      </xsl:template>
</xsl:stylesheet>


<?xml version="1.0" encoding="UTF-8"?>
<root>
    <p class="- topic/p ">To set the value of this property using CSS:
        <pre xml:space="preserve" class="- topic/pre ">
            PlotSeries {
            fills:#CC66FF, #9966CC, #9999CC;
            }
        </pre>
    </p>
    <p class="- topic/p ">To set the value of this property using MXML:
        <pre xml:space="preserve" class="- topic/pre ">
            &lt;mx:PlotSeries ... &gt;
              &lt;mx:fills&gt;
                &lt;mx:SolidColor color="0xCC66FF"/&gt;
                &lt;mx:SolidColor color="0x9966CC"/&gt;
                &lt;mx:SolidColor color="0x9999CC"/&gt;
              &lt;/mx:fills&gt;
            &lt;/mx:PlotSeries&gt;
        </pre>
    </p>
</root>

can you suggest what's going wrong or any other alternative for this?

Thanks,
Shailesh
0
Comment
Question by:ShaileshShinde
1 Comment
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 250 total points
ID: 20364176
The search and replace template is there to make sure that a
&lt; is replcaed by a &amp;lt;
resulting in the output you are receiving

this would work in this case as a template for <pre>

    <xsl:template match="pre">
        <xsl:variable name="product" select="@product| @class | @outputclass"/>
        <xsl:if test="string-length($product)=0 or not($product=concat($hiddenProductName,'only'))">
            <pre>
            <xsl:value-of disable-output-escaping="yes" select="."/>
            </pre>
        </xsl:if>
    </xsl:template>

cheers

Geert
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Auto Complete Using JQuery 5 81
Windows Standards for file storage. 3 26
How to i line up css containers from left to right 35 23
Animated .jpg? 13 81
When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question