Copied to clipboard

Flag this post as spam?

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


  • hickoryFornander 32 posts 52 karma points
    Jan 29, 2010 @ 12:29
    hickoryFornander
    0

    How do I list siblings and mark oneself?

    Hi! I need help to think :)

    I want to create a list of the siblings that exist to a page/node, including itself. When doing this I wish to mark the self-node so that I can add different css to that list object. Is that possible?

    Thanks!

    /too tired >S

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jan 29, 2010 @ 12:34
    Thomas Höhler
    1
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <ul>
        <xsl:for-each select="$currentPage/preceding-sibling">
          <li><xsl:value-of select="@nodeName"/></li>
        </xsl:for-each>
    <li><xsl:value-of select="$currentPage/@nodeName"/></li>
        <xsl:for-each select="$currentPage/following-sibling">
          <li><xsl:value-of select="@nodeName"/></li>
        </xsl:for-each>
      </ul>
    </xsl:template>

    hth, Thomas

    
    
                
  • hickoryFornander 32 posts 52 karma points
    Jan 30, 2010 @ 04:38
    hickoryFornander
    0

    Hi! Thank you so much! Been sleeping some now too and got it almost working :D The only thing missing is the link to the siblings.


    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <ul id="menuShowSiblings">


    <xsl:if test="count($currentPage/preceding-sibling::node) != 0">
        <xsl:for-each select="$currentPage/preceding-sibling::node() [string(data [@alias='hide']) != '1']">
          <li>
        <a href="#"> <!-- {umbraco.library:NiceUrl(@id)} -->
        <xsl:value-of select="string(./data [@alias='pageTitle'])"/>
        </a>
          </li>
        </xsl:for-each>
    </xsl:if>

    <li><xsl:attribute name="class">active</xsl:attribute>
        <xsl:value-of select="$currentPage/data [@alias='pageTitle']"/>
    </li>

    <xsl:if test="count($currentPage/following-sibling::node) != 0">
        <xsl:for-each select="$currentPage/following-sibling::node()[string(data [@alias='hide']) != '1']">
          <li>
        <a href="#"> <!-- {umbraco.library:NiceUrl(@id)} -->
        <xsl:value-of select="string(./data [@alias='pageTitle'])"/>   
        </a>
        </li>
        </xsl:for-each>
    </xsl:if>
    </ul>

    </xsl:template>

    My problem is that I get an xsl parsing error when I add the url to the sibling pages. :S Why?

     

    Thank you! :)

     

  • hickoryFornander 32 posts 52 karma points
    Jan 30, 2010 @ 04:53
    hickoryFornander
    0

    Hi! Ok, an update....it works to go forward :S. I can add the links to the following-sibling, but not the links to preceding-sibling. So the first page that only show the following-siblings works just fine, but not the rest because they use the preceding-sibling. And it is only with {umbraco.library:NiceUrl(@id)}, any other path works fine. Ehhh...why?

    <xsl:param name="currentPage"/>
    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul id="menuShowSiblings">

    <xsl:if test="count($currentPage/preceding-sibling::node) != 0">
        <xsl:for-each select="$currentPage/preceding-sibling::node() [string(data [@alias='hide']) != '1']">
          <li>
        <a href="#"> <!-- GAAAHAHHHAHAA  - parsing error when I add {umbraco.library:NiceUrl(@id)} -->
        <xsl:value-of select="string(./data [@alias='pageTitle'])"/>   
        </a>
        </li>
        </xsl:for-each>
    </xsl:if>

    <li><xsl:attribute name="class">active</xsl:attribute>
        <xsl:value-of select="$currentPage/data [@alias='pageTitle']"/>
    </li>

    <xsl:if test="count($currentPage/following-sibling::node) != 0">
        <xsl:for-each select="$currentPage/following-sibling::node()[string(data [@alias='hide']) != '1']">
          <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
        <xsl:value-of select="string(./data [@alias='pageTitle'])"/>   
        </a>
        </li>
        </xsl:for-each>
    </xsl:if>
    </ul>

    </xsl:template>

     

    Anyone with an idea?

    Thank you! :)

  • hickoryFornander 32 posts 52 karma points
    Jan 30, 2010 @ 08:50
    hickoryFornander
    0

    Sorry forgot to write the error message ...dooh! >S

    Error parsing the XSLT:

    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.ExecuteDelegate.Invoke(XmlQueryRuntime runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters)
    at umbraco.presentation.umbraco.developer.Xslt.xsltVisualize.visualizeDo_Click(Object sender, EventArgs e)

     

    ..beautiful huh?!

  • Stephan Lonntorp 195 posts 212 karma points
    Jan 30, 2010 @ 10:36
    Stephan Lonntorp
    0

    And if you check the box "Don't check for errors", when it saves, does it work?

     

    //S

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 30, 2010 @ 10:41
    Chriztian Steinmeier
    1

    Hi,

    Let's take a different approach - a little more XSLT-ish:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="umbraco.library"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <ul id="menuShowSiblings">
                <xsl:apply-templates select="$currentPage/../node" />
            </ul>
        </xsl:template>
    
        <!-- node template -->
        <xsl:template match="node">
            <li>
                <xsl:if test="$currentPage/@id = @id">
                    <xsl:attribute name="class">active</xsl:attribute>
                </xsl:if>
                <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="data[@alias = 'pageTitle']"/>
                </a>
            </li>
        </xsl:template>
    
        <!-- No output for nodes marked as hidden -->
        <xsl:template match="node[data[@alias = 'umbracoNaviHide'] = 1]" />
    
    </xsl:stylesheet>

    This uses a separate template for creating the list item and link; it uses a template to hide items instead of including that long XPath predicate in every select you might add in the future; finally, it applies templates to the parent node's children, instead of manually selecting preceding- and follwing-siblings.

    I'd advice you to use the 'standard' alias umbracoNaviHide for hiding nodes, to maximize compatibility with 3rd party packages and such.

    If you don't want a link around the $currentPage menuitem, you can use a choose statement, like this inside the template:

       <xsl:choose>
            <xsl:when test="$currentPage/@id = @id">
                <xsl:value-of select="data[@alias = 'pageTitle']" />
            </xsl:when>
            <xsl:otherwise>
                <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="data[@alias = 'pageTitle']" />
                </a>
            </xsl:otherwise>
        </xsl:choose>
    


    /Chriztian

  • hickoryFornander 32 posts 52 karma points
    Feb 01, 2010 @ 06:55
    hickoryFornander
    0

    Hi! Thank you so much for all your answers!!

    I tested:

    <?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:umbraco.library="urn:umbraco.library"
            exclude-result-prefixes="umbraco.library">

            <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

            <xsl:param name="currentPage" />
           
            <xsl:template match="/">
                    <ul id="menuShowSiblings">
                <!-- Extend this to check so that the sibling is not protected -->
                            <xsl:apply-templates select="$currentPage/../node [data[@alias = 'hide'] = 0 and (count(./node) &gt; 0)]" />
                    </ul>
            </xsl:template>
           
            <!-- node template -->
            <xsl:template match="node">
                    <li>   
                <xsl:choose>
                    <xsl:when test="$currentPage/@id = @id">
                        <xsl:attribute name="class">active</xsl:attribute>
                                    <xsl:value-of select="data[@alias = 'pageTitle']" />
                            </xsl:when>
                            <xsl:otherwise>
                                    <a href="{umbraco.library:NiceUrl(@id)}">
                                            <xsl:value-of select="data[@alias = 'pageTitle']" />
                                    </a>
                            </xsl:otherwise>
                </xsl:choose>
                    </li>
            </xsl:template>
    </xsl:stylesheet>

    AND it works! :D Thank you!

    I understand that it is better to use the "umbracoNaviHide". But I have a main menu where I do not want these subpages to be seen (there I use "umbracoNaviHide"), and I do not want to be confusing others by saying that it is the opposite for this menu. So a solution I came up with was to check for "hide" here :) I am new to Umbraco so if you have a better suggestion I am very interested in hearing :) It is fun to learn!

    Thanks!! :)

  • psiho 101 posts 96 karma points
    Oct 28, 2010 @ 16:57
    psiho
    0

    I'm trying for some time now but cannot figure out how to do this on new schema. "node" is not usable there as it can be several different things.

  • Rich Green 2246 posts 4008 karma points
    Oct 28, 2010 @ 17:25
  • psiho 101 posts 96 karma points
    Oct 28, 2010 @ 21:36
    psiho
    0

    Amazing tool Rich! Thx. Output works perfectly. Key was in "$currentPage/../* [@isDoc]" instead of old "$currentPage/../node"

Please Sign in or register to post replies

Write your reply to:

Draft