Insert xpath parameter but only if querystring not equal nothing or "all"
Maybe someone has asked this before, but I don't know what to search for. I want to create a for-each loop. But if the querystring "sortCountry" is not equal to nothing or to "all" then the for-each loop must find only the specifired countries. Does that make sence?
I'll demonstrate... This is code to be fired if the sortCountry != '' or sortCountry != 'all':
Hm... that dosen't make much sense to me. You suggest I loop thrugh the products WITH the parameter and inside the loop tells what to do WITHOUT the parameter...?
Is there a way to add a parameter to the for-each if sortCountry contains something?
Sorry what i wanted to suggest you was to choose make something like
<xsl:choose> <xsl:whentest="sortCountry != ''"> <!-- somthing funny happens --> <!-- Here you could also call a template where you will have your loop --> </xsl:when> <xsl:otherwise> <!-- Something Less Funny happpens --> <!-- another template where you will have another loop --> </xsl:otherwise> </xsl:choose>
Just to be sure of what normalize-space() does... if the variable contains let say: " this little test text ", will it then remove the spaces completely ("thislittletesttext") or just the spaces that isn't needed ("this little test text")?
normalize-space() removes leading and trailing whitespace, and converts runs of whitespace into a single space - imagine this:
<bodyText> Here I am
so for the demoing issue...
we can say.
</bodyText>
Then normalize-space(bodyText) would give you:
"Here I am so for the demoing issue... we can say."
Which is excellent for use in e.g. HTML attributes.
If the string starts as only whitespace, normalize-space() will return an empty string - and when you perform a test="" in XSLT the result will be sent through the boolean() function - and boolean(EMPTY STRING HERE) will return false(), so I've found it to be the best way to test if an element (or a variable) actually contains something.
(I know that was a way longer answer than necessary - hope it helps, though :-)
Insert xpath parameter but only if querystring not equal nothing or "all"
Maybe someone has asked this before, but I don't know what to search for. I want to create a for-each loop. But if the querystring "sortCountry" is not equal to nothing or to "all" then the for-each loop must find only the specifired countries. Does that make sence?
I'll demonstrate... This is code to be fired if the sortCountry != '' or sortCountry != 'all':
Otherwise:
Well, I kind of answared my own question here... I could use a choose. Let me hear your suggestions. Thanks
Hi kasper you could do something like
Hm... that dosen't make much sense to me. You suggest I loop thrugh the products WITH the parameter and inside the loop tells what to do WITHOUT the parameter...?
Is there a way to add a parameter to the for-each if sortCountry contains something?
Sorry what i wanted to suggest you was to choose make something like
Hi Kasper,
The best way to test stuff like this is with the normalize-space() function:
Also, take note of how to reduce duplication by using variables for intermediate steps...
/Chriztian
Hi Chriztian
Good point with the variables.
Just to be sure of what normalize-space() does... if the variable contains let say: " this little test text ", will it then remove the spaces completely ("thislittletesttext") or just the spaces that isn't needed ("this little test text")?
Hi Kasper,
normalize-space() removes leading and trailing whitespace, and converts runs of whitespace into a single space - imagine this:
Then normalize-space(bodyText) would give you:
Which is excellent for use in e.g. HTML attributes.
If the string starts as only whitespace, normalize-space() will return an empty string - and when you perform a test="" in XSLT the result will be sent through the boolean() function - and boolean(EMPTY STRING HERE) will return false(), so I've found it to be the best way to test if an element (or a variable) actually contains something.
(I know that was a way longer answer than necessary - hope it helps, though :-)
/Chriztian
It stands very clear for me now ;-)
Thanks for you both for your responses. Have a nice day
is working on a reply...