Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bart de Jonge 29 posts 51 karma points
    Aug 27, 2010 @ 17:43
    Bart de Jonge
    0

    make headerimages dynamic

    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

     

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 28, 2010 @ 00:04
    Chriztian Steinmeier
    1

    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

  • Rik Helsen 670 posts 873 karma points
    Aug 30, 2010 @ 10:36
    Rik Helsen
    0

    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
  • Rik Helsen 670 posts 873 karma points
    Aug 30, 2010 @ 10:39
    Rik Helsen
    0

    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>
Please Sign in or register to post replies

Write your reply to:

Draft