Copied to clipboard

Flag this post as spam?

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


  • adrianfriend 67 posts 68 karma points
    Sep 26, 2011 @ 18:20
    adrianfriend
    0

    Property via Variable

    Hi All,

    I have a few dropdowns that I need to filter a list on, these dropdowns correlate to existing properties on a DocType. So the question is how in 4.5 and higher can I filter a select based on a variable?

    Example - dropdown id = country, property alias = country ($filter). Selected value = 'Japan' ($text)

    <xsl:for-each select="$currentPage/* [$filter = $text]">

    Is something like that possible? I'm sure you could do it in the old schema with /data [@alias=string($filter)]

    TIA,

    Adrian

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 26, 2011 @ 18:45
    Chriztian Steinmeier
    1

    Hi Adrian,

    You're probably looking for the name() function:

    <xsl:for-each select="$currentPage/*[name() = $filter]">

    If you need to selected based on the value too, do this:

    <xsl:for-each select="$currentPage/*[name() = $filter][. = $text]">

    /Chriztian

  • adrianfriend 67 posts 68 karma points
    Sep 26, 2011 @ 18:59
    adrianfriend
    0

    Hi Chriztian,

    Doesnt seem to work (or output anything) - 

    <xsl:copy-of select="key('groupByName', name())[../@id = $centre/@id][name() = $filter][. = $text]"/>

    Thanks,

    Adrian

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 26, 2011 @ 19:54
    Chriztian Steinmeier
    0

    Hi Adrian,

    Could easily be a mismatch with the key() - try checking every step of the expression until it doesn't give you the expected results:

    <xsl:copy-of select="key('groupByName', name())" />
    <xsl:copy-of select="key('groupByName', name())[../@id = $centre/@id]" />
    <xsl:copy-of select="key('groupByName', name())[../@id = $centre/@id][name() = $filter]"/>
    <xsl:copy-of select="key('groupByName', name())[../@id = $centre/@id][name() = $filter][. = $text]"/>
    

    /Chriztian

  • adrianfriend 67 posts 68 karma points
    Sep 27, 2011 @ 12:25
    adrianfriend
    0

    Chriztian,

    Sorry man, none of the above give me what I need - any other ideas? The only other way I can think of doing it is add another xsl:choose and then test against what the $filter variable is as doing something like country = $text as that works.

    Adrian

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 27, 2011 @ 12:46
    Chriztian Steinmeier
    0

    No worries Adrian,

    What I meant was - does the first one (just the key()) give you the nodes from which you need to select the final? If so, does adding the parentId filter narrow 'em down but still return the wanted node(s)? And so on and so forth...

    Could you explain a little more about the scenario?

    /Chriztian

  • adrianfriend 67 posts 68 karma points
    Sep 27, 2011 @ 12:51
    adrianfriend
    0

    Chriztian,

    This is the one that selects the nodes I need - unfiltered. Then I have some dropdowns that then send querystrings back which I need to filter the list on i.e. $filter will be the property name and $text will be what I need to filter on (hope that made sense)

    <xsl:copy-ofselect="key('groupByName', name())[../@id = $centre/@id]"/>

    Thanks,

    Adrian

  • Richard 146 posts 168 karma points
    Sep 27, 2011 @ 12:55
    Richard
    0

    Adrian,

    I did the following, this was written in the old schema, and I used on the online converter to create the new schema code:

    <xsl:variable name="matchedNodes" select="$currentPage/* [@isDoc]"/>

    <xsl:variable name="filter" select="umbraco.library:RequestQueryString('country')" />

    <xsl:choose>
    <xsl:when test="$filter =''">
    <xsl:apply-templates select="$matchedNodes/* [@isDoc][position() &lt; 7]">
    <xsl:sort data-type="text" select="@createDate" order="descending"/>
    </xsl:apply-templates>
    </xsl:when>
    <xsl:otherwise>
    <xsl:apply-templates select="$matchedNodes[contains(./country,$filter)]">
    <xsl:sort data-type="text" select="@createDate" order="descending"/>
    </xsl:apply-templates>
    </xsl:otherwise>
    </xsl:choose>

    Then add your match template to display each record.

    Regards

    Richard

  • adrianfriend 67 posts 68 karma points
    Sep 27, 2011 @ 12:57
    adrianfriend
    0

    Hi Richard,

    Thanks but what I need to do is decide on the property I want dynamically - rather than knowing that I want 'country' - could be one of about 5 properties I want to filter on.

    Adrian

  • adrianfriend 67 posts 68 karma points
    Sep 27, 2011 @ 12:59
    adrianfriend
    0

    BTW - If I do 

    <xsl:copy-ofselect="key('groupByName', name())[../@id = $centre/@id][country = $text"/>

    It filters properly so the syntax is correct and the correct order. Just when trying to pass in dynamic properties it fails.

    Adrian

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 27, 2011 @ 13:05
    Chriztian Steinmeier
    0

    Ah . OK :-)

    This ouoghht to do it then:

    <xsl:copy-ofselect="key('groupByName', name())[../@id = $centre/@id][*[name() = $filter] = $text" />

    Missed that it was a step further down :-)

    /Chriztian

     

  • adrianfriend 67 posts 68 karma points
    Sep 27, 2011 @ 13:08
    adrianfriend
    0

    Chriztian,

    That worked perfectly :) I did try something similar yesterday but syntax must of been off somewhere.

    Once again you come to the rescue with your Ninja XSLT skills. I now owe you a few beers :)

    Adrian

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Sep 27, 2011 @ 13:30
    Chriztian Steinmeier
    0

    Why thank you!

    Two words I like a lot... "few beers" :-)

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft