I am having what I believe to be a similar problem is many places on my site. I have made a set up with multiple blogs and each blog has a different header image which is selected on dashboard for the blog. I have a simple macro doing this. i'd rather do it this way because it will be easier for people to switch out the artwork later. Anyways, I had this all set up so it worked on the home page for each blog...not thinking to test it on the articles page until further down the road. Doh! I'm having many problems like this and I believe it is my pathing. Here is one example of something I tried to rectify this...and got an error
I (apparently incorrectly) assumed that this would look for the blog that was an ancestor of this node and pull the alias bannerImage.
Not only does it not do this, it throws this error
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.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)
I've tried using this and similar in many macros and obviously my two-week-old knowledge of xslt is not helping. Hopefully I've missed something simple.
I do agree with you that I should be making sure that there is a value and wrapping it in an if statement but the statement I am using to call the images still returns that error if it is in the macro. I would understand if I was returning a wrong value but I'm not...it's giving me an error <<see above>>.
You are so close... the parsing error is due to the XPath syntax you used. The double-slash (//data) would return a node-set, as opposed to a string-value. Best bet would be to take a step back and work through the data you need.
<!-- assign the root blog node to a variable-->
<xsl:variable name="blog" select="$currentPage/ancestor-or-self::node[@nodeTypeAlias = 'Blog']" />
<!-- check if the blog node has a data element for 'banner image' -->
<xsl:if test="count($blog/data[@alias='bannerImage']) > 0 and $blog/data[@alias='bannerImage'] != ''">
<!-- assign the GetMedia to a variable -->
<xsl:variable name="media" select="umbraco.library:GetMedia($blog/data[@alias='bannerImage'], 0)" />
<!-- check that the media contains the data -->
<xsl:if test="count($media/data[@alias='umbracoFile']) > 0">
<!-- do whatever you want to do here -->
<xsl:value-of select="$media/data[@alias='umbracoFile']" />
</xsl:if>
</xsl:if>
If you want to read up a little more about GetMedia, I wrote a blog post about it a while ago:
Hmmm, odd. I'm not sure what I did but the error is gone...but its still not behaving properly. Thanks for your help so far. Now I'm back to the original issue. When I'm at the top level of the blog, the iamge shows up. The minutes that I go a node deeper, the image is gone, and I figured by using this code to grab the ancestor-or-self and look for the blog node type that I should have been able to get this image for all nodes below the blog.
@lee good catch but that still isn't the issue. I changed that out but oddly enough it grabs the image on the self node but not if it is one of the post nodes.
The frustration has been whatever issue is holding me up with this issue is the same pathing issue that is catching me with several macros so I must be missing some sort of important concept.
You are correct about it only working for the blog nodes. As a side note, if I remove that <xsl:if part, thats when I get an error while saving. It still works though on the page.
Ancestor-or-self node issues
Hello all,
I am having what I believe to be a similar problem is many places on my site. I have made a set up with multiple blogs and each blog has a different header image which is selected on dashboard for the blog. I have a simple macro doing this. i'd rather do it this way because it will be easier for people to switch out the artwork later. Anyways, I had this all set up so it worked on the home page for each blog...not thinking to test it on the articles page until further down the road. Doh! I'm having many problems like this and I believe it is my pathing. Here is one example of something I tried to rectify this...and got an error
I (apparently incorrectly) assumed that this would look for the blog that was an ancestor of this node and pull the alias bannerImage.
Not only does it not do this, it throws this error
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.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)
I've tried using this and similar in many macros and obviously my two-week-old knowledge of xslt is not helping. Hopefully I've missed something simple.
Thanks for any insights.
The GetMedia library function needs an integer as input, and you have to validate that it's not empty before.
Wrap you function in an if-statement
<xsl:if test="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']//data [@alias='bannerImage'] != ''"/>
...
</xsl:if>
>Tommy
Hey Tommy,
Thanks for the quick response.
If I ignore the image I want added for a minute and use this code
I get a lovely
Error parsing XSLT file: \xslt\HeaderImage.xslt
I do agree with you that I should be making sure that there is a value and wrapping it in an if statement but the statement I am using to call the images still returns that error if it is in the macro. I would understand if I was returning a wrong value but I'm not...it's giving me an error <<see above>>.
Could you post the full xslt ?
Sure...
When do you get the error - when saving or on the page when using it?
Hi Andrew,
You are so close... the parsing error is due to the XPath syntax you used. The double-slash (//data) would return a node-set, as opposed to a string-value. Best bet would be to take a step back and work through the data you need.
If you want to read up a little more about GetMedia, I wrote a blog post about it a while ago:
http://blog.leekelleher.com/2009/11/30/how-to-use-umbraco-library-getmedia-in-xslt/
Cheers, Lee.
Hmmm, odd. I'm not sure what I did but the error is gone...but its still not behaving properly. Thanks for your help so far. Now I'm back to the original issue. When I'm at the top level of the blog, the iamge shows up. The minutes that I go a node deeper, the image is gone, and I figured by using this code to grab the ancestor-or-self and look for the blog node type that I should have been able to get this image for all nodes below the blog.
The nodes are set up like this
root
--blog @bannerImage
----blog post (these nodes don't find that image)
----blog post
--blog @bannerImage
----blog post
----blogpost
@lee good catch but that still isn't the issue. I changed that out but oddly enough it grabs the image on the self node but not if it is one of the post nodes.
The frustration has been whatever issue is holding me up with this issue is the same pathing issue that is catching me with several macros so I must be missing some sort of important concept.
do you get any img tag at all in your blog post? I assume your blog post nodes are of some other type than Blog.
oops,
that only goes for the blog nodes
@Tommy I do not get any images unless they were part of the post. Any images (blog roll, header graphic, etc.) do not show up
You are correct about it only working for the blog nodes. As a side note, if I remove that <xsl:if part, thats when I get an error while saving. It still works though on the page.
But if you use your original source code the outer if-statement will only work for the blog nodes, right?
OOOOOOOOO wow. I get what you are saying. Yes you are correct...but unsure of my way around that
Use Lee's code would probably work- he defines the right path as a variable used in testing, getmedia etc.
Duhhh.
Thank you SOOOOO much for your help
is working on a reply...