Copied to clipboard

Flag this post as spam?

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


  • Peter Alcock 113 posts 176 karma points
    Jun 25, 2012 @ 18:36
    Peter Alcock
    0

    Display child node at any level

    Hi guys

    Looking for some help again! Ive got some xslt to display 2 random nodes from root i.e Home, Settings with my structure but i want it to display a random 2 nodes (just nodename) for a specific doc type alias in this case 'AProperty'.

    The nodes for AProperty can be on multiple levels though so unsure how to seahc the whole node structure in one instead of having [@level = 2] etc.

     

    Hope makes sense, my basic structure goes, it's based on properties in locations, each location however can have sub locations which also contain 'properties'

    Home

       -  Location Page

            - AProperty Page

            - Location Page

                   -AProperty Page

    <?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:msxsl="urn:schemas-microsoft-com:xslt"
        xmlns:rdm="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="msxml msxsl umbraco.library rdm">
        <xsl:output method="xml" omit-xml-declaration="yes" />

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage" />
        <xsl:variable name="root" select="$currentPage/ancestor-or-self::root" />

    <xsl:variable name="maxItems" select="number(2)" />
    <msxsl:script language="JavaScript" implements-prefix="rdm">
        function Random(r) { return Math.ceil(Math.random()*r); }
    </msxsl:script>
    <xsl:template match="/">
    <ul>
      <xsl:for-each select="$root/* [@isDoc] ">
    <xsl:sort select="rdm:Random($maxItems)" order="descending" />
        <xsl:if test="position() &lt;= $maxItems">
          <li><xsl:value-of select="@nodeName"/></li>
        </xsl:if>
    </xsl:for-each>
          </ul>
    </xsl:template>
    </xsl:stylesheet>
  • Jan-Willem de Bruyn 17 posts 38 karma points
    Jun 27, 2012 @ 10:54
    Jan-Willem de Bruyn
    0

    Hello, maybe you can use <xsl:for-each select="$root/descendant-or-self::* [@isDoc and @nodeTypeAlias = 'AProperty'] "> (see example) or did you mean a property on the node? 

     

    <?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:msxsl="urn:schemas-microsoft-com:xslt"
        xmlns:rdm="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="msxml msxsl umbraco.library rdm">
        <xsl:outputmethod="xml"omit-xml-declaration="yes"/>

    <xsl:outputmethod="xml"omit-xml-declaration="yes"/>
    <xsl:paramname="currentPage"/>
        <xsl:variablename="root"select="$currentPage/ancestor-or-self::root"/>

    <xsl:variablename="maxItems"select="number(2)"/>
    <msxsl:scriptlanguage="JavaScript"implements-prefix="rdm">
        function Random(r) { return Math.ceil(Math.random()*r); }
    </msxsl:script>
    <xsl:templatematch="/">
    <ul>
      <xsl:for-each select="$root/descendant-or-self::* [@isDoc and @nodeTypeAlias = 'AProperty'] ">
    <xsl:sortselect="rdm:Random($maxItems)"order="descending"/>
        <xsl:iftest="position() &lt;= $maxItems">
          <li><xsl:value-ofselect="@nodeName"/></li>
        </xsl:if>
    </xsl:for-each>
          </ul>
    </xsl:template>
    </xsl:stylesheet>

     

Please Sign in or register to post replies

Write your reply to:

Draft