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?
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?
<!-- 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 = '*'])" />
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
Hi Doogie,
The hardcoded one should look like this, to match what the other one is doing:
(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
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.
Okay,
Here's how you can do that:
/Chriztian
Superb I see what you have done there and it will help further down the code too. Thanks a lot.
Doogie.
is working on a reply...