Copied to clipboard

Flag this post as spam?

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


  • Peter Bradsted Bodenhoff 27 posts 47 karma points
    Jan 12, 2010 @ 12:56
    Peter Bradsted Bodenhoff
    0

    xslt-problem with GetMedia

    Hi

    I have this xslt-file:

    --------------------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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"/>
    <xsl:template match="/">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data[@alias='frontPicture'], 'false')/data[@alias = 'umbracoFile']" />
    </xsl:template>
    </xsl:stylesheet>
    --------------------------------------------------------

    when i test it in the visualizer it works as I want it to - but when I try to save it I get an error:

    --------------------------------------------------------
    (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, Boolean closeWriter)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter 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)
    --------------------------------------------------------

    What is wrong?? .........

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jan 12, 2010 @ 13:03
    Peter Dijksterhuis
    3

    Hi,

    you have 2 options here:

    1: disable checking for errors upon saving 

    2: use the following code:

    <xsl:if test="$currentPage/data[@alias='frontPicture'] != '' ">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data[@alias='frontPicture'], 'false')/data[@alias = 'umbracoFile']" />
    </xsl:if>
    The preview works because you have an active node. Upon saving, you don't have a node to test against, hence the error (Getmedia requires an integer, if nothing present, it's not an integer).
    HTH,
    Peter

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 13, 2010 @ 18:51
    Kim Andersen
    0

    Yeah, you should use the examplecode that Peter wrote in his post.

    Otherwise, you could edit the file outside of Umbraco in some sort of code editor. I myself use Visual Studio all the time.

  • Eric 35 posts 55 karma points
    Jan 14, 2010 @ 10:48
    Eric
    0

    Yes, I think Peter's code (sol. 2) is best practice. I always do that way and never have problem.

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Jan 14, 2010 @ 11:19
    Lee Kelleher
    0

    Hi Peter [BB], yes follow what Peter D suggested, by having an IF condition around the value-of / GetMedia.

    I wrote a blog post a few weeks ago about how to safely handle the GetMedia calls in XSLT - have a read...

    http://blog.leekelleher.com/2009/11/30/how-to-use-umbraco-library-getmedia-in-xslt/

    Cheers, Lee.

  • 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.

Please Sign in or register to post replies