Convert XSLT Variables to Upper or Lower Case

I had a situation where I needed to compare a query string parameter to a value in a list inside a data view web part in SharePoint Designer. If the two values matched in regards to the text, but did not match in regards to case (for example: SomeWord vs. someword), they would not match when compared in the XSLT. It appears that the version of XSLT used in a data view web parts doesn’t support the lower-case() and upper-case() functions.

Luckily, I discovered a workaround. Originally, I had the following code:

<xsl:variable name="Rows" select=/dsQueryResponse/MyList/Rows/Row[normalize-space(@MyField) = $myQueryStringVar]“/>

At first, I tried this:

<xsl:variable name="Rows" select=/dsQueryResponse/MyList/Rows/Row[normalize-space(lower-case(@MyField)) = lower-case($myQueryStringVar)]“/>

But I received an error that the function was not supported. The workaround is as follows:

<xsl:variable name="lower">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="upper">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>

<xsl:variable name="Rows" select="/dsQueryResponse/MyList/Rows/Row[normalize-space(translate(@MyField,$upper,$lower)) = translate($myQueryStringVar,$upper,$lower)]“/>

This entry was posted in Tips and Tricks, Web Parts and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Vlad
    Posted October 29, 2008 at 10:53 am | Permalink

    This is great! Thank you. I was wondering how did you compare a query string parameter to a value in a list inside a data view web part in SharePoint Designer? Do you have any XSLT code for it? Thank you.

  2. ccondon
    Posted November 3, 2008 at 12:57 pm | Permalink

    Vlad,

    First, you need to create a ParameterBinding, like this:

    <ParameterBindings>
    <ParameterBinding Name="myVar" Location="QueryString(myQSVar)" />
    </ParameterBindings>

    Then, you need to add this within your stylesheet (<xsl:stylesheet>):

    <xsl:param name="myVar"></xsl:param>

    And finally, add something like this within your template (<xsl:template>):

    <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[@ID = $myVar]“/>

  3. SZ
    Posted December 8, 2008 at 7:56 pm | Permalink

    Thx for the tip, worked great. Was manipulating strings from files uploaded to a Picture Library, everything I did yesterday worked fine, new uploads didn’t work. Drove me crazy till I realized the file extensions today were Uppercase. Your solution fixed me in 5 min.

    abcdefghijklmnopqrstuvwxyz
    ABCDEFGHIJKLMNOPQRSTUVWXYZ

    @ID=#@FileRef=#@_ModerationStatus=

    Of course someone will now tell me this was a bad way to build the a string to the thumbnail, but I’m GREEN.

    Thx again

One Trackback

  1. [...] Convert XSLT Variables to Upper or Lower Case [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*