Pages

Showing posts with label format. Show all posts
Showing posts with label format. Show all posts

Monday, March 16, 2015

How-To remove HTMLTags to display plain text using XSLT


In this post i will be showing how you can use XSLT to strip out HTML tags from HTML data sources (Rss, sharepoint list item, database field ... etc) and display plain text

Below is the function to remove HTML tags:

  <xsl:template name="removeHtmlTags">
    <xsl:param name="html"/>
    <xsl:choose>
      <xsl:when test="contains($html, '&lt;')">
        <xsl:value-of select="substring-before($html, '&lt;')"/>
        <!-- Recurse through HTML -->
        <xsl:call-template name="removeHtmlTags">
          <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$html"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

You can see that the function name is removeHtmlTags which accepts one argument / parameter named as html which is my Description field that contains HTML Tags.
Logic is simple, its a recursive function which finds for '&lt;' that is '<' means starting of any HTML Tag and take out the substring after this '<' Tag using substring-before() function as substring-before($html, '&lt;') and again call the function with the rest of the string left after  '&gt;' that is '>' Tag.

This is how this function will be called:

    <xsl:template name="RssCell">
        <xsl:variable name="pureText">
            <xsl:call-template name="removeHtmlTags">
                <xsl:with-param name="html" select="DescriptionField" />
            </xsl:call-template>
        </xsl:variable>

        <div height='40' class='blog_text'>
            <xsl:value-of disable-output-escaping="yes"  select="substring($pureText, 0, 175)"/>
        </div>
    </xsl:template>

One Variable is declared as pureText. removeHtmlTags() function will strip out the HTML Tags and return the Plain Text values in this pureText variable.
I am passsin DescriptionField that is my DB Field with HTML Tags.

Finally, I am displaying max 175 chars of Plain Text as substring($pureText, 0, 175) inside a DIV.

Thats It!


Reference

Saturday, May 17, 2014

SOLVED: 'Download Unsuccessful' Error Notification in Android

Problem:
For a while, it has been an exhausting issue to fix with website users that when trying to download pdf files through the android stock browser or android chrome browser or some other browsers.. 
they get a 'Download Unsuccessful' notification.

Solution:
Now it got clear once understood that android file type association requires certain applications to open specific file types..

As long as the file type you are trying to open\download (pdf, rar, zip, word, …) is unknown or not associated with an existing application.. it won't open\download..

So all you need to do is :
·        If you want to open\download pdf file, install Acrobat Reader first through android PlayStore.
·        If you want to open\download rar, zip etc.. download and install Archidroid from android PlayStore.
·        … and so on.

Conclusion:  
At the end it's not an issue in your website you have to fix.. just file association needs to be fixed in users devices.. that's all J

Saturday, November 23, 2013

asp DataGrid Format Text Field as DateTime

Here I'm binding to a DataGrid on an asp page, the Database contains a text field that holds a date text on the format "yyyyMMdd" and I want to show the date in the format "day MonthName year",

All I had to do is adding to the Datagrid <Columns> a TemplateColumn with the following binding:

<# DateTime.ParseExact(DataBinder.Eval(Container.DataItem, "DATE_Field").ToString(), "yyyyMMdd", new System.Globalization.CultureInfo("ar-sa")).ToString("dd MMM yyyy", new System.Globalization.CultureInfo("ar-sa"))%>

For example, let's say the database stores "14350117" in the field DATE_Field as text, the above binding will let it appear as  on the page..