Yeh, the xslt parser checks what you've written against the topmost node. Often the properties you are referencing don't exist on this page, causing the error. Putting the checks in just allows you to save, but is also best practice as it should prevent any unsightly "error parsing bleh.xslt" errors on your page in the event that the data is not what you expect it to be.
GetMedia problem
Hi
Im a total beginner at Umbraco and XSLT, but I just dont understand why this doesnt work!
This works fine and displays the image ID
<xsl:for-each select="$currentPage/node">
<xsl:value-of select="data [@alias = 'personImg']"/>
</xsl:for-each>
In this case the image ID is 1067. If i hardcode the ID the image displays nicely:
<img src="{umbraco.library:GetMedia(1067, false)/data [@alias='umbracoFile']}"/>
...but if I try the following:
<xsl:for-each select="$currentPage/node">
<img src="{umbraco.library:GetMedia(data [@alias='personImg'], false)}"/>
</xsl:for-each>
I get the following error when trying to save the XSLT:
(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
ved Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
ved Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
ved System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
ved System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
ved System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
ved System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
ved System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
ved umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
Help appreciated!
Nicolai
Hi Nicolai
Try writing something like this:
Does this help?
/Jan
You'll probably need to wrap a check around the getMedia call as seen in this thread -> http://our.umbraco.org/forum/using/ui-questions/4685-umbracoLibraryGetMedia%28%29-Problem?p=0#comment16882
Dan
Thanks for the quick responses!
Jan:
@id wont do the trick as im in the parent documenttype (or am i missing something?).
Dan:
Thanks a lot that worked out. Guess the check is mandatory! Not a very informative error message!
Thanks
Nicolai
Yeh, the xslt parser checks what you've written against the topmost node. Often the properties you are referencing don't exist on this page, causing the error. Putting the checks in just allows you to save, but is also best practice as it should prevent any unsightly "error parsing bleh.xslt" errors on your page in the event that the data is not what you expect it to be.
Dan
Ah that makes sense.
Thank you Dan
Nicolai
is working on a reply...