Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello,
I use an xslt to make the headerimages in a website dynamic.
<xsl:choose> <xsl:when test="$currentPage/ancestor-or-self::node [string(data[@alias='HeaderImage'])!=''][1] /data[@alias='HeaderImage'] != ''"> <xsl:value-of select="umbraco.library:GetMedia($currentPage/ancestor-or-self::node [data[@alias='HeaderImage']!=''][1] /data[@alias='HeaderImage'],'false')/data [@alias = 'umbracoFile']"/> </xsl:when> <xsl:otherwise> /media/6899/recycled.jpg </xsl:otherwise> </xsl:choose>
this works fine for umbraco 4.0.2.1
can someone tell me what I have to change to make it work for umbraco 4.5.2
thanks Bart
Hi Bart,
Try something along the lines of this:
<xsl:variable name="headerImageID" select="$currentPage/ancestor-or-self::*[normalize-space(HeaderImage)][1]/HeaderImage" /> <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($headerImageID, false())" /> <xsl:choose> <xsl:when test="normalize-space($mediaNode/umbracoFile)"> <xsl:value-of select="$mediaNode/umbracoFile" /> </xsl:when> <xsl:otherwise> <xsl:text>/media/6899/recycled.jpg</xsl:text> </xsl:otherwise> </xsl:choose>
/Chriztian
Thanks Chriztian, but we're still getting errors, i think it's because the property exists everywhere, but it's only has a value on a few pages...
<xsl:variable name="headerImageID" select="$currentPage/ancestor-or-self::*[normalize-space(headerimage)][1]/headerimage" />
doesn't throw errors, but the second variable (MediaNode) does when i save the page...
This is the error i get when i save it:
Error occuredSystem.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 mediaNode(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) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver) 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
Nevermind, The solution was only declaring the medianode variable if data was available!
pretty much finished code:
<xsl:output method="xml" omit-xml-declaration="yes" /><xsl:param name="currentPage"/> <xsl:variable name="headerImageID" select="$currentPage/ancestor-or-self::*[normalize-space(headerimage)][1]/headerimage" /><xsl:template match="/"> <xsl:choose> <xsl:when test="$currentPage/ancestor-or-self::* [@isDoc and string(headerimage) != ''] "> <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($headerImageID, false())" /> <xsl:value-of select="$mediaNode/umbracoFile" /> </xsl:when> <xsl:otherwise> /media/6899/recycled.jpg </xsl:otherwise> </xsl:choose></xsl:template></xsl:stylesheet>
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
make headerimages dynamic
Hello,
I use an xslt to make the headerimages in a website dynamic.
this works fine for umbraco 4.0.2.1
can someone tell me what I have to change to make it work for umbraco 4.5.2
thanks Bart
Hi Bart,
Try something along the lines of this:
/Chriztian
Thanks Chriztian, but we're still getting errors, i think it's because the property exists everywhere, but it's only has a value on a few pages...
<xsl:variable name="headerImageID" select="$currentPage/ancestor-or-self::*[normalize-space(headerimage)][1]/headerimage" />
doesn't throw errors, but the second variable (MediaNode) does when i save the page...
This is the error i get when i save it:
Nevermind, The solution was only declaring the medianode variable if data was available!
pretty much finished code:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.