Copied to clipboard

Flag this post as spam?

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


  • FarmFreshCode 225 posts 422 karma points
    Jan 27, 2015 @ 16:38
    FarmFreshCode
    0

    Get All Children From Parent Node with Specific DocType

    So right now I am using:

    <xsl:for-each select="umbraco.library:GetXmlAll()//SDProfile [@isDoc] ">

    .. which is ok.. but it grabs ALL of the SDProfiles created in my site.. and thats NOT what I want. I only want to check my parent node and grab all of the children under that 1 parent.

    "SDProfile" is the doctype that I want to pull... so here is a graphic to help illustrate my issue and node tree...

    Thanks in advance for your help!

     

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 27, 2015 @ 21:53
    Jan Skovgaard
    0

    Hi FarmFreshCode

    What version of Umbraco are you using? The below snippet assumes that it's at least version 4.5.x

    You actually don't need to call the GetXmlAll() extension at all.

    In the macro you're using on the "Doctoral Students" you should be able to simply write (From the top of my mind, it's been a while since I coded XSLT :-/)

    <xsl:for-each select="$currentPage/ancestor-or-self::*[@isDoc and @level ='1'/descendant::SDProfile]">
    

    So what this should do is go to the node at level 1 (The Student Directory node) and then it should find every descendant of with the SDProfile alias.

    It might be a good idea to write it out in a textarea to make sure any nodes are returned at all like

    <textarea>
     <xsl:copy-of select="$currentPage/ancestor-or-self::*[@isDoc and @level ='1'/descendant::SDProfile]" />
    </textarea>
    

    A nice tool to use in order to visualize, which nodes are selected using the different axes is available here http://pimpmyxslt.com/axesviz.aspx - Credits to @greystate aka Chriztian "XSLT" Steinmeier :)

    Also it might be handy to look at the XML structure in the /App_Data/umbraco.config file.

    Hope this makes sense!

    /Jan

  • FarmFreshCode 225 posts 422 karma points
    Jan 27, 2015 @ 22:07
    FarmFreshCode
    0

    Hi Jan,

    Thanks for the suggestion..I'm currently using v4.8

    I tried your code and it just through back an error. :-(
    "Error occured

    System.Xml.Xsl.XslLoadException: Expression must evaluate to a node-set.
    ...r-or-self::*[@isDoc and @level = -->'1'<-- /descendant::SDProfile] An error occurred at D:\Inetpub\wwwroot\Umbraco\xslt\635579715280572925_temp.xslt(24,7).
    at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)"

    Technically I think the student Directory Node is like level 3 in my full site tree..

    I have been able to get a few others to "kind of work"... but I'm still basically writing the same thing where it's calling ALL of the SDProfiles and not just the ones inside my immediate parent:

    <xsl:for-each select="$currentPage/ancestor::root//SDProfile ">
    <xsl:for-each select="$currentPage/ancestor::*[@isDoc]//SDProfile ">


    Those 2 seem to give me the same result as:

    <xsl:for-eachselect="umbraco.library:GetXmlAll()//SDProfile [@isDoc] ">

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 27, 2015 @ 22:11
    Jan Skovgaard
    100

    Hi FarmFreshCode

    Hmm, yeah...I have a typo in my code snippet. It should read

     <xsl:copy-of select="$currentPage/ancestor-or-self::*[@isDoc and @level ='1']/descendant::SDProfile" /> - Forgot to close the bracket the right place.
    

    I think you should give it a spin again since there can be some performance issues with using the // trick that you're using above as far as I know.

    /Jan

  • FarmFreshCode 225 posts 422 karma points
    Jan 27, 2015 @ 22:30
    FarmFreshCode
    1

    THANKS JAN!

    I made just a few tweaks to it and now it looks like it's working great:

    * I changed it back to a "for-each" statement and changed the @level to 3 and that seemed to do it!

    <xsl:for-each select="$currentPage/ancestor-or-self::*[@isDoc and @level ='3']/descendant::SDProfile" >
Please Sign in or register to post replies

Write your reply to:

Draft