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?
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?
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)
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: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) > 0)]" /> </ul> </xsl:template>
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!
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
hth, Thomas
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! :)
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! :)
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?!
And if you check the box "Don't check for errors", when it saves, does it work?
//S
Hi,
Let's take a different approach - a little more XSLT-ish:
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:
/Chriztian
Hi! Thank you so much for all your answers!!
I tested:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<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) > 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!! :)
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.
psiho,
Did you try http://blackpoint.dk/umbraco-workbench/tools/convert-xml-schema-to-45-.aspx ?
Rich
Amazing tool Rich! Thx. Output works perfectly. Key was in "$currentPage/../* [@isDoc]" instead of old "$currentPage/../node"
is working on a reply...