But when i try to save my xslt macro i get this message
Error occured
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, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current) at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}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.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
If your are trying to create a top navigation, you'll need to create a for-each statement around your <li>-elements. I think that the reason to why your saving fails, is because you can't just write umbraco.library:NiceUrl(@id) when you're not inside of a loop.
To get the hopepage-node (the one called KIM) you can do something like this:
$currentPage/ancestor-or-self::node[@level='1']
This means that you should be able to create a topnavigation with something like this:
Note that I have put the level (1) inside of a variable. You don't have to do this if you don't want to, you can just replace the $level variable with the number 1 if you prefer.
But I hope the above code can help you out a little.
By the way Dan. The code I provided was ment for the old XML schema, which I assume you are using from reading the first code you posted. If you do use the new schema, we'll have to make some minor changes to the code.
Another tip if you don't already know it. When you create e new XSLT-file from within Umbraco, you can choose from several "XSLT-snippets" meaning that the new file will already include some code with different purposes. One of those precoded options are a navigation XSLT-file. You could try taking a look at it if you want to play around a bit.
Thanks for both your replies however i have tried using the code snippets previously for my full navigation, (the code i posted up was a seperate macro as i just wanted to try it out) i can always get my top nav using level 1 as a variable but it never has KIM, in it. no matter what i try, its really annoying and i cant quite figure out why it wont show it.
I have even tried the below code now, which i am passing in the node id for KIM but it still shows the error message in my original post, i also tried placing this inside a loop just to see if this made a difference, but unfortunatley not,
<!-- Input the documenttype you want here --> <!-- Typically '1' for topnavigtaion and '2' for 2nd level --> <!-- Use div elements around this macro combined with css --> <!-- for styling the navigation --> <xsl:variable name="level" select="1"/> <xsl:variable name="isDoc" select="string('HomePage')"/> <xsl:template match="/">
<!-- The fun starts here --> <ul> <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> <xsl:sort select="@nodeName" order="ascending"/> <li> <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node[@level=1]/@id)}"> <xsl:value-of select="$currentPage/ancestor-or-self::node[@level=1]/@nodeName"/> </a> </li> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> </a> </li> <li> <xsl:value-of select="umbraco.library:GetXmlNodeById(1060)"/> <a href="{umbraco.library:NiceUrl(@id)}">Home</a> </li> </xsl:for-each> </ul> </xsl:template> </xsl:stylesheet>
This gives a class called 'current' to the current top level item page you are on, and then gives the top level item a class called 'parent' when you are on one of the 2nd level pages below that item. If that makes sense?!
I think I'm a bit confused about what you want to achieve here :S
You want to create a topnavigation including a link to your homepage? Or are you just trying to create a link to your homepage in a single macro?
And which version on Umbraco are you using?
The new code that you provided is a mix of the new and the old XML schema, and even if it did work it would create a pretty weird navigation with three <li>-elements created per childnode of the homepage.
Sam, thanks for the code, havent tried it yet but will give it a go, i have got it working myself now. The code i pasted above was again something i added together to try and show what i wanted.
I was trying to create a top level navigation of my items under kim, so business, consumer, technical etc etc, and then a link back to the home page / KIM however any time i added the level in ie 1, it simply wont show KIM, and brings up that error. However i solved this by using this, and i can now do exactly what i wanted.
<xsl:template match="/">
<!-- start writing XSLT --> <ul> <!-- Get our KIM / Home item --> <li> <a href="{umbraco.library:NiceUrl($currentPage/../@id)}">Home </a> </li> <!-- add our other set links for intranet, and .co.uk --> <li> <a href="http://www.t-mobile.co.uk">T-Mobile.co.uk</a> </li> </ul> </xsl:template>
I think clicking your home link (as it is now) would take you back one level rather than go back to the actual homepage. That's fine if you only have level one pages on your site, but if you go deeper, your home link wont take you back to your homepage. I just tried your code a minute ago on my site and when I was in a 3rd level page, clicking on home took me up one level rather than back to the homepage.
System.OverflowException: Value was either too large or too small for an Int32.
at System.Convert.ToInt32(Double value)
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 System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument,
XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter
writer)
at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String
fileName, String oldName, String fileContents, Boolean ignoreDebugging)
Does $currentPage/ancestor-or-self::node[last()]/@id takes the id of the page or something else? (>>
at System.Convert.ToInt32(Double value)<<) If it is the id - why it is of type double? Is it necessary to make some casting before? Please, help someone. I know just a few of xslt.
Well in this case you might not need the @isDoc. The @isDoc is an attribute thats put on the actual nodes. This means, that if an element in the XML has this attribute, it's a node from the content tree.
It's just to make sure that we actually grab a node, and not some field from the node.
But in your case, you also have the @level attribute, and this will not occour on any element that's anot a node as far as I'm concerned.
I still don't really see the point? Do you have an example of when missing the @isDoc out would become a problem? That would probably clarify it for me. Thanks for the help.
What I'm trying to say is what other element would there be on the content tree other than a node?
I think it makes sense to have the attribute since I think that you'll otherwise also parse media nodes since * selects all nodes in a document. So it makes sense that it only looks at those that are in fact a document and not a media node/media item.
You are creating a submenu macro, and in this situation you want to count how many childnodes the current page (let's just say you are currently standing on the Homepage-node) has.Then you could do something like this:
<xsl:value-of select="count($currentPage/*)" />
but this will count both the childnodes as well as the elements that's not nodes in the content tree. The above example would return 5.
But you only want to count the elements that's actually real nodes. To do this you would do this:
XSLT - Why Cant i get my root node
Hi Guys
Im trying to get my root node so that i can add it to my navigation as a home link
My site structure looks like this
The code i am trying to use is this
<?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: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="/">
<xsl:value-of select="$currentPage/ancestor-or-self::node[last()]/@id"/>
<ul>
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
But when i try to save my xslt macro i get this message
Error occured
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, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}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.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
Could someone give me so help please.
Thanks
Dan
I can't be certain as I've only just started using xslt myself but I'll try and help :) try removing your
<xsl:value-of select="$currentPage/ancestor-or-self::node[last()]/@id"/>
Not sure what that value-of select is actually doing there? ...and try this, I use this to add a home link:
<ul>
<li>
<a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node[@level=1]/@id)}">
<span><xsl:value-of select="$currentPage/ancestor-or-self::node[@level=1]/@nodeName"/></span>
</a>
</li>
<li>
(then add the rest of your list in here)
</li>
</ul>
Hope this helps.
Sam.
Hi Dan
If your are trying to create a top navigation, you'll need to create a for-each statement around your <li>-elements. I think that the reason to why your saving fails, is because you can't just write umbraco.library:NiceUrl(@id) when you're not inside of a loop.
To get the hopepage-node (the one called KIM) you can do something like this:
$currentPage/ancestor-or-self::node[@level='1']
This means that you should be able to create a topnavigation with something like this:
Note that I have put the level (1) inside of a variable. You don't have to do this if you don't want to, you can just replace the $level variable with the number 1 if you prefer.
But I hope the above code can help you out a little.
/Kim A
By the way Dan. The code I provided was ment for the old XML schema, which I assume you are using from reading the first code you posted. If you do use the new schema, we'll have to make some minor changes to the code.
Another tip if you don't already know it. When you create e new XSLT-file from within Umbraco, you can choose from several "XSLT-snippets" meaning that the new file will already include some code with different purposes. One of those precoded options are a navigation XSLT-file. You could try taking a look at it if you want to play around a bit.
/Kim A
Hi Kim and Sam
Thanks for both your replies however i have tried using the code snippets previously for my full navigation, (the code i posted up was a seperate macro as i just wanted to try it out) i can always get my top nav using level 1 as a variable but it never has KIM, in it. no matter what i try, its really annoying and i cant quite figure out why it wont show it.
I have even tried the below code now, which i am passing in the node id for KIM but it still shows the error message in my original post, i also tried placing this inside a loop just to see if this made a difference, but unfortunatley not,
<?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:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Input the documenttype you want here -->
<!-- Typically '1' for topnavigtaion and '2' for 2nd level -->
<!-- Use div elements around this macro combined with css -->
<!-- for styling the navigation -->
<xsl:variable name="level" select="1"/>
<xsl:variable name="isDoc" select="string('HomePage')"/>
<xsl:template match="/">
<!-- The fun starts here -->
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:sort select="@nodeName" order="ascending"/>
<li>
<a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node[@level=1]/@id)}">
<xsl:value-of select="$currentPage/ancestor-or-self::node[@level=1]/@nodeName"/>
</a>
</li>
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
<li>
<xsl:value-of select="umbraco.library:GetXmlNodeById(1060)"/>
<a href="{umbraco.library:NiceUrl(@id)}">Home</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
I use this as my top navigation, try it out, see if you can tweak it to work for you :)
This gives a class called 'current' to the current top level item page you are on, and then gives the top level item a class called 'parent' when you are on one of the 2nd level pages below that item. If that makes sense?!
Give it a whirl, see what happens :)
Sam.
Hi again Dan.
I think I'm a bit confused about what you want to achieve here :S
You want to create a topnavigation including a link to your homepage? Or are you just trying to create a link to your homepage in a single macro?
And which version on Umbraco are you using?
The new code that you provided is a mix of the new and the old XML schema, and even if it did work it would create a pretty weird navigation with three <li>-elements created per childnode of the homepage.
/Kim A
Hi Kim and Sam,
Sam, thanks for the code, havent tried it yet but will give it a go, i have got it working myself now. The code i pasted above was again something i added together to try and show what i wanted.
I was trying to create a top level navigation of my items under kim, so business, consumer, technical etc etc, and then a link back to the home page / KIM however any time i added the level in ie 1, it simply wont show KIM, and brings up that error. However i solved this by using this, and i can now do exactly what i wanted.
<xsl:template match="/">
<!-- start writing XSLT -->
<ul>
<!-- Get our KIM / Home item -->
<li>
<a href="{umbraco.library:NiceUrl($currentPage/../@id)}">Home
</a>
</li>
<!-- add our other set links for intranet, and .co.uk -->
<li>
<a href="http://www.t-mobile.co.uk">T-Mobile.co.uk</a>
</li>
</ul>
</xsl:template>
</xsl:stylesheet>
Hi Dan,
I think clicking your home link (as it is now) would take you back one level rather than go back to the actual homepage. That's fine if you only have level one pages on your site, but if you go deeper, your home link wont take you back to your homepage. I just tried your code a minute ago on my site and when I was in a 3rd level page, clicking on home took me up one level rather than back to the homepage.
I think this is the code you need to use:
rather than:
It should work, I'm using umbraco 4.0.4.2 by the way :)
Sam.
Hello!
I`m experiencing the same difficultires as dan. I am trying to reach the root nod of my site. I tried thew both
and
but in both cases I`ve got this error message:
Error occured
System.OverflowException: Value was either too large or too small for an Int32.
at System.Convert.ToInt32(Double value)
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 System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
Does $currentPage/ancestor-or-self::node[last()]/@id takes the id of the page or something else? (>> at System.Convert.ToInt32(Double value)<<) If it is the id - why it is of type double? Is it necessary to make some casting before? Please, help someone. I know just a few of xslt.
Thansks,
Aleksandar
Hi Aleksandar
Are you using the legacy XML schema?
If you are not, then you might wanna try this snippet out:
/Kim A
Hi Aleksander,
Could you post the whole xslt file? Maybe another part of it is causing the error.
Thanks,
Sam.
Hi Kim.
This was the decision, thanks a lot.
Regards,
Aleksandar
Kim,
If you've got a spare minute, please could you explain why you need the @isDoc?
I use this:
and it works fine without. I'm still not 100% on what the isDoc does, even after reading an explanation on another thread...
Thanks,
Sam.
Hi Sam,
Well in this case you might not need the @isDoc. The @isDoc is an attribute thats put on the actual nodes. This means, that if an element in the XML has this attribute, it's a node from the content tree.
It's just to make sure that we actually grab a node, and not some field from the node.
But in your case, you also have the @level attribute, and this will not occour on any element that's anot a node as far as I'm concerned.
So you should be fine :)
/Kim A
Hi Kim,
I still don't really see the point? Do you have an example of when missing the @isDoc out would become a problem? That would probably clarify it for me. Thanks for the help.
What I'm trying to say is what other element would there be on the content tree other than a node?
Sam.
Hi Sam
I think it makes sense to have the attribute since I think that you'll otherwise also parse media nodes since * selects all nodes in a document. So it makes sense that it only looks at those that are in fact a document and not a media node/media item.
Does this make sense to you?
/Jan
Hi Sam
How about this example:
Let's say you have this XML:
You are creating a submenu macro, and in this situation you want to count how many childnodes the current page (let's just say you are currently standing on the Homepage-node) has.Then you could do something like this:
but this will count both the childnodes as well as the elements that's not nodes in the content tree. The above example would return 5.
But you only want to count the elements that's actually real nodes. To do this you would do this:
This would return the correct value 3.
Does that make sense?
/Kim A
Ah yes, thanks Kim & Jan,
That's cleared it up :) thanks again.
Sam.
is working on a reply...