How to get value at a position from a split result
Hello everybody :)
I want to test each value from a split string separated by a coma. How do i grab the value at a position in the split ie what is the value of split variable at position 2?
I'm currently trying to test for related articles by tags. If there are 2 or more articles found then show list of articles otherwise show nothing.
The code snippet is below with necessary information. The ???????? is the code bit that I'm unsure of how to write?
<!-- loop through each item --> <xsl:for-each select="$contentSplit/value"> <xsl:variable name="contentSplitItem" select="." /> <xsl:if test="position() = 2"> <!-- second in list --> </xsl:if> </xsl:for-each>
<!-- are there more than 2 --> <xsl:if test="count($contentSplit/value) > 2">
Just wanted to say, if you're ever stuck wondering what XML is returned from an extension I would recommend putting it into a textarea on screen. This usually removes any guess work or mystery.
How to get value at a position from a split result
Hello everybody :)
I want to test each value from a split string separated by a coma. How do i grab the value at a position in the split ie what is the value of split variable at position 2?
I'm currently trying to test for related articles by tags. If there are 2 or more articles found then show list of articles otherwise show nothing.
The code snippet is below with necessary information. The ???????? is the code bit that I'm unsure of how to write?
If you split the CSV using umbraco.library:Split then for-each through the values, you can test position() to find the current "tag number"
Hope this helps,
Dan
Hi,
Dan's approach is great.
Just wanted to say, if you're ever stuck wondering what XML is returned from an extension I would recommend putting it into a textarea on screen. This usually removes any guess work or mystery.
For example
Cheers,
Chris
Hi.
Dan's approach works well, but if you want only second item you should use
<xsl:value-of select="contentSplit/value[2]" />
It has better performance
Wow - thanks Dan, Chris and Petr for your responses - 2 solutions and 1 technique for developing/bug fixing - totally awesome....
Just to put an answer into the loop of things, I've updated the snippet of code above from:
to:
and it works like a charm :)
is working on a reply...