18 Mar
This is something a SharePoint programmer usually faces. I hope following solution give you help to move ahead.
Removing all HTML tags from a string
<xsl:template name="removeHtmlTags">
<xsl:param name="html"/>
<xsl:choose>
<xsl:when test="contains($html, ‘<’)">
<xsl:value-of select="substring-before($html, ‘<’)"/>
<!– Recurse through HTML –>
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="substring-after($html, ‘>’)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$html"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Thanks.
17 Mar
While working with SharePoint numerical columns, we do face situations when we do not need the thousand separator from the numbers. For the same, please use the following code.
<xsl:variable name="MyPrice">
<xsl:choose>
<xsl:when test="contains(@Price, ‘,’)">
<xsl:value-of select="concat(substring-before(@Price, ‘,’), substring-after(@Price, ‘,’))" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@Price" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
There is always a better solution to what we do, so if you know anything better, do let me know.
16 Mar
While working in SharePoint dataviews, we need to compare dates several times to find out a larger one. While I wondered around this and I see there is no direct function to do this.
I found a workaround which I generally use.
1. Create 2 variables from dates. I’m converting both dates to US format and then to a number with year, month and date sequence to ensure correctness.
<xsl:variable name="ExpiryDate1" select="number(ddwrt:FormatDateTime(string(@ExpirationDate), 1033, ‘yyyyMMdd’))"/>
<xsl:variable name="OtherDate2" select="number(ddwrt:FormatDateTime(string(@OtherDate), 1033, ‘yyyyMMdd’))"/>
2. Compare them to find out which one is greater
<xsl:choose>
<xsl:when test=’ExpirationDate-OtherDate >= 0′>
// Do Something
</xsl:when>
<xsl:otherwise>
// Do Something
</xsl:otherwise>
</xsl:choose>
I don’t claim that this the best solution I have got, while it works very well. If you know anything better, please share!