Copied to clipboard

Flag this post as spam?

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


  • Doogie Talons 183 posts 318 karma points
    Aug 29, 2012 @ 15:20
    Doogie Talons
    0

    Difficulty passing * Wildcard as a Variable

    Hi all.

    I need to pass a wildcard to a variable if a selection is empty. 

    Wondering why this is not working.

    <xsl:variable name="townVariable">  
    <xsl:choose>
    <xsl:when test="umbraco.library:RequestQueryString('town') ='' or umbraco.library:RequestQueryString('town') = '*' ">
    *
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:RequestQueryString('town')"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>  

    <xsl:variable name="numberOfRecords" select="count($feedXml/root/property[town=$townVariable])" />

     

     

     

    If I hard code it as ... 

    <xsl:variable name="numberOfRecords" select="count($feedXml/root/property[town=*])" />

    Then it works fine.


    Weird, I hope someone can help.

     

    Doogie

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 9x admin c-trib
    Aug 29, 2012 @ 15:34
    Chriztian Steinmeier
    0

    Hi Doogie,

    The hardcoded one should look like this, to match what the other one is doing:

    <xsl:variable name="numberOfRecords" select="count($feedXml/root/property[town = '*'])" />

    (Note the single quotes around the star)

    Do you want to count <property> elements with <town>*</town> content, or you mean to use it as a wildcard (to select any property) when no town is specified in the URL?

    /Chriztian

  • Doogie Talons 183 posts 318 karma points
    Aug 29, 2012 @ 15:41
    Doogie Talons
    0

    Yeah I thought that...

     

    when I mess around for example with 

    <xsl:variable name="numberOfRecords" select="count($feedXml/root/property[town=*])" />

    It returns all the records 571

    If I use as you said 

    <xsl:variable name="numberOfRecords" select="count($feedXml/root/property[town='*'])" />

    it returns non...

    So what I am tring to achieve is to pass a variable to the select so it ends up read as 

    <xsl:variable name="numberOfRecords" select="count($feedXml/root/property[town=*])" />

    If empty.

    Basically it's to select a specific list of "propertys" from an  xml and to return them all if none is present.

     

    Do you want to count <property> elements with <town>*</town> content, or you mean to use it as a wildcard (to select any property) when no town is specified in the URL?

    I want it to treat the * as a wildcard. 

     

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 9x admin c-trib
    Aug 29, 2012 @ 16:01
    Chriztian Steinmeier
    1

    Okay,

    Here's how you can do that:

    <!-- Grab all <property> elements from the feed -->
    <xsl:variable name="properties" select="$feedXml/root/property" />
    
    <!-- Grab param from QueryString -->
    <xsl:variable name="townParam" select="umbraco.library:RequestQueryString('town')" />
    
    <!-- Filter by selected town param -->
    <xsl:variable name="filtered" select="$properties[town = $townParam]" />
    
    <!-- Count the filtered (or all if town is empty or the wildcard character) -->
    <xsl:variable name="numberOfRecords" select="count($filtered | $properties[$townParam = '' or $townParam = '*'])" />
    

    /Chriztian

  • Doogie Talons 183 posts 318 karma points
    Aug 29, 2012 @ 16:15
    Doogie Talons
    0

    Superb I see what you have done there and it will help further down the code too. Thanks a lot.

    Doogie.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies