Copied to clipboard

Flag this post as spam?

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


  • Chad 65 posts 129 karma points c-trib
    Jul 01, 2010 @ 09:56
    Chad
    0

    child and descendant axis doesn't seem to work correctly :/

    Ok, maybe my understand of XSLT is wrong (highly likely), but here's the drama:

    <xsl:apply-templates select="$currentPage//child::Packages" />

    Then I have separate templates for the different child nodes:

    <xsl:template match="CountryPackageCategory">...

    <xsl:template match="AggregatePackageCategory">...

    But the drama is, that the content from the actual Packages

    node, is being dumped to the output as well.

    According to: http://pimpmyxslt.com/axesviz.aspx?contextNode=1069&axis=child#screen

    That shouldn't be the case?

  • Neil Campbell 58 posts 182 karma points
    Jul 01, 2010 @ 10:06
    Neil Campbell
    0

    What you are doing there is getting any child nodes of the currentPage that have the alias=Packages.

    Try <xsl:apply-templates select="$currentPage/descendant::Packages [@isDoc]/descendant::* [@isDoc]" />

    The above code is assuming you are running this macro from the home page.

    It's hard to solve without knowing what your xml or content tree looks like.

  • Chad 65 posts 129 karma points c-trib
    Jul 01, 2010 @ 10:11
    Chad
    0

    I'm using schema 4.5 FYI. My Content Tree looks like:

    Home
    --Packages
    ----CountryPackage1
    ----CountryPackage2
    ----AggregatePackage1

    I just want CountryPackage1, CountryPackage2, AggregatePackage1 - Nothing else.

    The XPath you've provided fixed the initial problem I had, but it also then output the child nodes of CountryPackage1

  • Neil Campbell 58 posts 182 karma points
    Jul 01, 2010 @ 10:14
    Neil Campbell
    0

    Cool cool. Now set a level that you want to limit at, as below:

    <xsl:apply-templates select="$currentPage/descendant::Packages [@isDoc]/descendant::* [@isDoc and @level = 3]" />

    if you want to just select country package nodes at level 3 then use:

    <xsl:apply-templates select="$currentPage/descendant::Packages [@isDoc]/descendant::countryPackage [@isDoc and @level = 3]" />


    Cheers,
    Neil

  • Chad 65 posts 129 karma points c-trib
    Jul 01, 2010 @ 10:18
    Chad
    0

    That works. Although I'm still not 100% clear on why my original XPath was no good :)

    Also, the what does the @isDoc attribute represent?

  • Neil Campbell 58 posts 182 karma points
    Jul 01, 2010 @ 10:25
    Neil Campbell
    0

    Your first xsl was saying on the currentPage (lets say your at home), get me all nodes of type "Packages". What you are wanting to do is find the node type "Packages" and then get me all it's child nodes (who's alias I may or may not know). Does that kind of make sense?

    @isDoc is just an attribute that make sure the xml element being returned is an umbraco doc. If you omit isDoc the xsl will give you all the properties of the doc you are returning. It is required for the new xml schema.

    Cheers,
    Neil

  • Chad 65 posts 129 karma points c-trib
    Jul 01, 2010 @ 10:31
    Chad
    0

    Ahhhh.... **cue lightbulb**.. Right my understand of the Axes format was all messed up. It was saying, get me all the child nodes of the current page, that are packages, not get me all the child nodes of all the packages.

     

    Thanks heaps for your help!

  • Neil Campbell 58 posts 182 karma points
    Jul 01, 2010 @ 10:33
    Neil Campbell
    0

    Haha, love the ah haaa moments. Yep that's it!
    No worries at all :)

    Cheers,
    Neil

  • Chad 65 posts 129 karma points c-trib
    Jul 01, 2010 @ 10:43
    Chad
    0

    Armed with my new found knowledge, I've updated this:

    <xsl:apply-templates select="$currentPage/descendant::Packages [@isDoc]/descendant::* [@isDoc and @level = 3]" />

    to:

    <xsl:apply-templates select="$currentPage/descendant::Packages [@isDoc]/child::node() [@isDoc]" />

Please Sign in or register to post replies

Write your reply to:

Draft