Copied to clipboard

Flag this post as spam?

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


  • Jose Guay 5 posts 76 karma points
    Aug 25, 2016 @ 21:13
    Jose Guay
    0

    Multinode Treepicker XPath Start Node based on another MNTP

    Hi all.

    I have a site for which I'm working with information listings. These listings have a main category and potentially many sub categories. Sub categories belong to a single category. E.g.:

    Cat 1

    --- Sub Cat X

    --- Sub Cat Y

    --- Sub Cat Z

    Cat 2

    --- Sub Cat A

    --- Sub Cat B

    --- Sub Cat C

    I have created a document type for categories and another for sub categories and the structure works well. For my listing document type I added a property with an MNTP for selecting a single category from content (works great). Then added a second MNTP for the sub categories, and tried to use XPath to dynamically load the sub categories based on the category selected.

    If I do something like:

    $root/home/listingCategories/category[@id=1220]
    

    It works perfectly. Of course, the category is hard-coded. But when I try to load the ID from the selected category:

    $root/home/listingCategories/category[@id=$current/mainCategory/@id]
    

    I get an error:

    An error occured

    Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

    EXCEPTION DETAILS

    System.Xml.XPath.XPathException: Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

    Can anyone help me with the correct way to write the XPath to select the sub categories using a MNTP dynamically from the selected category?

    Thanks!!!

  • Sotiris Filippidis 286 posts 1501 karma points
    Oct 18, 2016 @ 16:49
    Sotiris Filippidis
    1

    I think it won't let you use $current inside a predicate.

    Another issue I can see is that you are using @id as the target value. If your MNTP property alias is mainCategory, then you must use mainCategory/text() as the id is stored as a CDATA element.

    What I've done in similar cases is to try and find the node that contains the "first" MNTP, e.g. if it's on the home page I'd do:

    $root/home/listingCategories/category[@id=./ancestor-or-self::home/mainCategory/text()]
    

    Of course this is only doable if the "first" MNTP is somewhere specific. On more generic scenarios, this could do the job:

    $root/home/listingCategories/category[@id=./ancestor-or-self::node()[@id=./@id]/mainCategory/text()]
    

    (Don't ask about the /ancestor-or-self::node()[@id=./@id], it wouldn't work with a simple ./ and I can't tell why).

    Finally, one more thing I've noticed is that while in earlier Umbraco versions changing the value of the "first" picker and saving would automatically have the dependent picker update its root when you clicked it, this is no longer the case and the dependent picker will not update its root until you reload the page or navigate away and come back.

Please Sign in or register to post replies

Write your reply to:

Draft