Copied to clipboard

Flag this post as spam?

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


  • Sebastian Dammark 583 posts 1407 karma points
    Apr 06, 2011 @ 14:50
    Sebastian Dammark
    0

    Filtering with keys and position()

    Any ideas how to combine position and keys.

    I have some documents that are tagged and I find the tagged documents using keys like this:

    <xsl:key name="filtred_news" match="News" use="tags/XPathCheckBoxList/nodeId"/>
    <xsl:param name="currentPage"/>
    
    <xsl:template match="/">
        <xsl:apply-templates select="$currentPage/ancestor-or-self::Frontpage/Newslist">
            <xsl:with-param name="tags" select="macro/tags" />
            <xsl:with-param name="items" select="macro/items" />
        </xsl:apply-templates>
    </xsl:template>
    
    <xsl:template match="Newslist">
        <xsl:param name="tags" />
        <xsl:param name="items" />
    
        <ul class="news">
            <xsl:choose>
                <xsl:when test="string-length($tags) &gt; 0">
                    <xsl:apply-templates select="key('filtred_news',$tags)" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates select="descendant::News[position() &lt;= $items]" />
                </xsl:otherwise>
            </xsl:choose>
        </ul>
    </xsl:template>

    If you see in the otherwise apply, I limit the number of outputs to 5 using a macro parameter.

    How do I do the same when using keys ?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 06, 2011 @ 21:03
    Chriztian Steinmeier
    0

    Hi Sebastian,

    Actually, you should be able to use the same predicate on that statement because apply-templates sets the current node list, which is where position() is calculated from:

    <xsl:apply-templates select="key('filtred_news', $tags)[position() &lt;= $items]" />

    I'm a little curious as to how the $tags parameter will work when there's more than one tag in there - does that do what you expect?

    /Chriztian

  • Sebastian Dammark 583 posts 1407 karma points
    Apr 07, 2011 @ 09:17
    Sebastian Dammark
    0

    Thought I tried that ... but apparently not ;)

    Regarding the tags stuff, the client can only select 1 tag at the moment.  But it will be possible to select multiple later on, but right now it's not possible to select multiple documents as a macro parameter.  All tags are created as documents in the tree.

    At that time it will need a remake.

Please Sign in or register to post replies

Write your reply to:

Draft