Solved

Disable output escaping

Posted on 2007-11-27
1
912 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

635 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