Copied to clipboard

Flag this post as spam?

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


  • Jeff Chapin 18 posts 39 karma points
    Mar 31, 2011 @ 06:44
    Jeff Chapin
    0

    Is it possible to list the root's children?

    Is it possible to list the root's children?
    For example - I'll use the thecogworks demo as a visual aide just because we can all see it.
    http://demo.thecogworks.co.uk/umbraco/umbraco.aspx#content
    Their tree structure looks like this:

    Content
        |
        +--Cog-Demo
        |   
        +--Blog

    Is it possible to write an XSLT to output 'Cog-Demo' and 'Blog' (I'm not worried about the formating right now.)
    I tried using  '/child::*' to start at the root and list one level below, but it doesn't work. 
    I suspect XSLT can't start that high.  See below.
           
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="msxml umbraco.library">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
      <!-- Get the root's children --> 
      <xsl:variable name="RootChild" select="/child::*" />
      <xsl:for-each select="$RootChild" >
        <xsl:value-of select="@nodeName"/> <br />
      </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

  • Pasang Tamang 258 posts 458 karma points
    Mar 31, 2011 @ 06:56
  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 31, 2011 @ 08:09
    Kim Andersen
    0

    Hi Jeff

    Try this:

    <xsl:variable name="root" select="$currentPage/ancestor-or-self::root" />
    <xsl:for-each select="$root/*[@isDoc]">
    <xsl:value-of select="@nodeName" />
    </xsl:for-each>

    /Kim A

  • Jeff Chapin 18 posts 39 karma points
    Mar 31, 2011 @ 17:28
    Jeff Chapin
    0

    Kim - Thanks your example works!

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 31, 2011 @ 18:57
    Kim Andersen
    0

    Great to hear Jeff. I'm glad the code worked :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft