I have some code that that's calling various templates from within templates (to compare 2 comma separated lists) ... Once I'm at the bottom level though, i.e. I've found what I'm looking for, how do I limit the output to a certain number?
I can't use position() because that's the position of the node in the original for-each. I basically only want to output a couple of these match.
Depending on your scenario (which I'm having a little trouble figuring out) you can try various options. The count(preceding::li) is a good one, but somehow you allude to that not working, or..?
Passing a value on from template to template using parameters is another way you might be able to solve it.
Sorry, didn't explain well... (it's complicated!)... but basically at the very bottom level of my code I output the result. I want to add in some blurb that limits the number of outputted <li> to 3. I can't do this check higher up the code because I'm doing other bits (that's what the link to comparing comma lists was about)
It looks to me like preceding-sibling is refering to nodes, where as I want it to refer to the outputted code. Is that not possible?
count(preceding::li) returns 0 in this, as does preceding-sibling::li
preceding-sibling:: (and all the other axes) works on the "input tree" not the "output tree", so of course you can't check for any <li> elements - I should have seen that right away :-)
Normally, you'd do this by limiting the applied templates, but since you say you can't do the check above, you're probably in for some hair-pulling...
You'll need to "do the math", so to speak, and figure out if the item you're going to output should be allowed to render itself;
Can you figure it out by checking for preceding-siblings of the same type as the one you rendering? E.g.:
Thanks again for reply... That didn't work (outputing the count gave values 28, 24, 17, 5 etc) ... Basics below. We have lots of 'info guides' on the site, I want to pull through the latest 3 info guides based on certain categories (infoGuideFilter - multi checkbox)
(it's only working if one category selected just now, I can worry about that after!)
<!-- Tags on current matched document --> <xsl:variable name="itemTags" select="Exslt.ExsltStrings:split($item/infoGuideCategories, ',')" />
<!-- Run match against node sets from split() --> <xsl:variable name="isMatch"> <xsl:call-template name="tokensMatch"> <xsl:with-param name="set1" select="$tags"/> <xsl:with-param name="set2" select="$itemTags"/> </xsl:call-template> </xsl:variable>
<!-- tokensMatch template will return a string with an X for each tag matched - so an empty string is no match, any non-empty string a match --> <xsl:if test="string($isMatch) != ''"> <!-- match found --> <xsl:call-template name="matchedNode"> <xsl:with-param name="item" select="$item" /> </xsl:call-template>
How to get position() in 'sub' templates
Hi,
I have some code that that's calling various templates from within templates (to compare 2 comma separated lists) ... Once I'm at the bottom level though, i.e. I've found what I'm looking for, how do I limit the output to a certain number?
I can't use position() because that's the position of the node in the original for-each. I basically only want to output a couple of these match.
Rest of the code is based on : http://our.umbraco.org/forum/developers/xslt/25099-How-to-get-position%28%29-in-%27sub%27-templates
(couldn't edit post)
Hey Paul,
You seemed to have linked back to the same (this) post?
Regards
Rich
Let's try that again...!
http://our.umbraco.org/forum/developers/xslt/9684-Compare-2-comma-separated-strings?p=1
I was just linking to this to show that the point I want to start the counting is buried 3 templates deep.
Hi Paul,
Depending on your scenario (which I'm having a little trouble figuring out) you can try various options. The count(preceding::li) is a good one, but somehow you allude to that not working, or..?
Passing a value on from template to template using parameters is another way you might be able to solve it.
/Chriztian
Sorry, didn't explain well... (it's complicated!)... but basically at the very bottom level of my code I output the result. I want to add in some blurb that limits the number of outputted <li> to 3. I can't do this check higher up the code because I'm doing other bits (that's what the link to comparing comma lists was about)
It looks to me like preceding-sibling is refering to nodes, where as I want it to refer to the outputted code. Is that not possible?
count(preceding::li) returns 0 in this, as does preceding-sibling::li
Thanks for any help,
Hi Paul,
Yes, of course (!) - I totally didn't catch that.
preceding-sibling:: (and all the other axes) works on the "input tree" not the "output tree", so of course you can't check for any <li> elements - I should have seen that right away :-)
Normally, you'd do this by limiting the applied templates, but since you say you can't do the check above, you're probably in for some hair-pulling...
You'll need to "do the math", so to speak, and figure out if the item you're going to output should be allowed to render itself;
Can you figure it out by checking for preceding-siblings of the same type as the one you rendering? E.g.:
- or is there more to it?
/Chriztian
Thanks again for reply... That didn't work (outputing the count gave values 28, 24, 17, 5 etc) ... Basics below. We have lots of 'info guides' on the site, I want to pull through the latest 3 info guides based on certain categories (infoGuideFilter - multi checkbox)
(it's only working if one category selected just now, I can worry about that after!)
is working on a reply...