Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Garrett Fisher 341 posts 496 karma points
    Mar 05, 2014 @ 19:19
    Garrett Fisher
    0

    Comparing Strings While Ignoring Letter Case --- XSLT concat() / FilterNodes()

    Hi, I have an interesting problem in a macro wherein I am building a search filter for use with ucomponents.xml:FilterNodes().

    The filter variable I am bulding works great with the dropdowns but when I am searching properties for a text string, my routine will only return lettercase matches. I am familiar with using the Exslt.ExsltStrings:lowercase() method, but because of how I am building this string using the concat function, I can force the original string to a given case but can't figure out how to do it on the property values with which I am comparing it inside the concat(). Here is the code (look for the "case-insensitve" comments):


    <xsl:variable name="filter">
      <xsl:if test="normalize-space($contains)">
        <xsl:variable name="containsString">
          <xsl:text>"xsl:text>
          CASE-INSENSITIVE
          <xsl:value-of select="$contains"/>
          <xsl:text>"xsl:text>
        xsl:variable>
        CASE-INSENSITIVE
        <xsl:value-of select="
            concat('[contains(@nodeName, ', $containsString, ')
            or contains(resourceDescription, ', $containsString, ')
            or contains(mediaType, ', $containsString, ')
            ]')" />
      xsl:if>
      <xsl:if test="normalize-space($type)">
        <xsl:variable name="mediaTypeString">
          <xsl:text>"xsl:text>
          <xsl:value-of select="umbraco.library:GetPreValueAsString($type)"/>
          <xsl:text>"xsl:text>
        xsl:variable>
        <xsl:value-of select="concat('[mediaType = ', $mediaTypeString, ']')" />
      xsl:if>
      <xsl:if test="normalize-space($usecase)">
        <xsl:value-of select="concat('[resourceUseCases//nodeId = ', $usecase, ']')" />         
      xsl:if>
      <xsl:if test="normalize-space($industry)">
        <xsl:value-of select="concat('[resourceIndustries//nodeId = ', $industry, ']')" />              
      xsl:if>
      <xsl:if test="normalize-space($product)">
        <xsl:value-of select="concat('[resourceProducts//nodeId = ', $product, ']')" />         
      xsl:if>
      <xsl:if test="not(normalize-space(concat($contains, $type, $usecase, $industry, $product)))">
        <xsl:text>[true()]xsl:text>
      xsl:if>
    xsl:variable>


    <xsl:variable name="filteredResources">
      <xsl:choose>
        <xsl:when test="normalize-space(concat($contains, $type, $usecase, $industry, $product))">
          <root>
            <xsl:copy-of select="ucomponents.xml:FilterNodes($currentPage, concat('
              ancestor-or-self::Home[@isDoc]//Resources[1][@isDoc]/ResourceType
              [@isDoc][not(umbracoNaviHide=1)]//*
              [@isDoc][not(umbracoNaviHide=1)]
              [(name()="LeadProtectedFile" and normalize-space(resourceFile))
              or
              (name()="LeadProtectedVideo" and normalize-space(embedCode))]',
              $filter))"/>
          root>
        xsl:when>
        <xsl:otherwise>
          <root>
            <xsl:copy-of select="$currentPage/ancestor-or-self::Home[@isDoc]//Resources[1]/ResourceType
              [@isDoc][not(umbracoNaviHide=1)]//*
              [@isDoc][not(umbracoNaviHide=1)]
              [(name()="LeadProtectedFile" and normalize-space(resourceFile))
              or
              (name()="LeadProtectedVideo" and normalize-space(embedCode))]"/>
          root>
        xsl:otherwise>
      xsl:choose>  
    xsl:variable>

    I have struggled mightily with this -- just don't know how I can call a function inside the concat with all of the single and double quotes already going on, it's confusing me!

    Thanks in advance,

    Garrett

Please Sign in or register to post replies

Write your reply to:

Draft