Copied to clipboard

Flag this post as spam?

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


  • Sean Holmesby 61 posts 82 karma points
    Mar 30, 2011 @ 01:50
    Sean Holmesby
    0

    GetMedia and NiceUrl acting weird

    What is wrong with my XSLT? I am using the latest version of Umbraco, and I've found some weird things happening with my XSLT.

    I had an issue last night where I wanted to display the images from items in my 'Sponsors' folder. Each sponsor item had an image (using a Media Picker field called 'sponsorImage') and a link to another page on the site (using a Content Picker field called 'sponsorLink').

    Looking on the internet, I found that the way I had to display the images was to do the following:-

    <xsl:for-each select="$sponsorNode/child::sponsorListing">

          <xsl:variable name="mediaUrl" select="umbraco.library:GetMedia(./data [@alias = 'sponsorImage'], 0)/data [@alias = 'umbracoFile']" />

    <img src="{$mediaUrl}" />

    </xsl:for-each>

    This didn't work. After hours of googling, and trying different things, I found that the syntax '/data [@alias...' wasn't required, and so my code now looks (and works proplerly) like this:-

    <xsl:for-each select="$sponsorNode/child::sponsorListing">

    <xsl:variable name="mediaUrl" select="umbraco.library:GetMedia(sponsorImage, 0)/umbracoFile" />

    </xsl:for-each>

    Is this some new (shorter) syntax that doesn't seem to be documented anywhere?

     

    The next step, which I am stuck on, is I now want to link to the content item that is chosen in the Content Picker field for each of my sponser items.

     

    Everywhere seems to suggest I can just do this:-

    <xsl:variable name="linkUrl" select="umbraco.library:NiceUrl(sponsorLink)" />

    ...but this doesn't work.

     

    What is going on here?!?!?!

    The value of 'sponsorLink' seems fine (I check it through <xsl:value-of> and they all return a four digit ID)....and if I hard-code a value it works fine as well. (i.e if I use <xsl:variable name="linkUrl" select="umbraco.library:NiceUrl(1070)" />)

    Am I losing my mind?

  • Daniel Bardi 927 posts 2562 karma points
    Mar 30, 2011 @ 03:06
    Daniel Bardi
    0

    Has of version 4.5, the xml schema changed, hence the change format of getting property values.

    Your NiceUrl format is correct... create the link like this

    <a href="{umbraco.library:NiceUrl(sponserLink)}">Sponser Link</a>
  • Sean Holmesby 61 posts 82 karma points
    Mar 30, 2011 @ 03:59
    Sean Holmesby
    0

    Hi, thanks for responding.

    That explains the reason why the GetMedia wasn't working, however I am still having issues with the NiceUrl thing. I tried that line of code with my field, and am still getting an error.

    I've seen people give an extended call stack, that pinpoints the problem better, however all I see is

    'Error parsing XSLT file: \xslt\listSponsors.xslt'

    Is there something I can enable so I can get more information about what the issue is?

  • Daniel Bardi 927 posts 2562 karma points
    Mar 30, 2011 @ 04:09
    Daniel Bardi
    1

    Does the xslt save properly?

    You can test the xslt in the editor.. might give you more info.

    Select all the text in the editor and click the last button on the editor tooldbar.

    Post back the result.

  • Sean Holmesby 61 posts 82 karma points
    Mar 30, 2011 @ 04:30
    Sean Holmesby
    0

    OK cool.... Here's the output:- Is it an issue with the four digit ID I'm passing in?

     

    Error parsing the XSLT:

    System.OverflowException: Value was either too large or too small for an Int32. at System.Convert.ToInt32(Double value) 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 System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters) at umbraco.presentation.umbraco.developer.Xslt.xsltVisualize.visualizeDo_Click(Object sender, EventArgs e)

  • Daniel Bardi 927 posts 2562 karma points
    Mar 30, 2011 @ 04:55
    Daniel Bardi
    0

    No... I'm sure it's fine... I forgot to tell you to set the value of the parameters before testing.

    The error is because you don't have values for those parameters in test mode.

    Can you post the xslt?

  • Sean Holmesby 61 posts 82 karma points
    Mar 30, 2011 @ 05:18
    Sean Holmesby
    0

    Oh, I found my issue!!!!

    When I first started, my link field was just called 'link'. Then I changed it over later to have the alias 'sponsorLink'.

    A link for one of my sponsors was set when the alias was the old value, so in the XSLT loop, there was no value for 'sponsorLink', but there was one for 'link'.

    This was causing the NiceUrl function to stuff up because I was passing a null value in.

    To fix the problem, I went to the sponsor in Umbraco that had the old link set, and set it again. Now it has a value for 'sponsorLink'.

    I will also put some code in that will catch when a value is not set in the Content Picker.....

     

    What a bastard of a problem! The thing that made everything look fine was the fact that Umbraco still showed that a link existed for the old alias in the content picker!!!

    Oh well, that teaches me to protect against invalid values more.... haha....

     

    Thanks for your help.

Please Sign in or register to post replies

Write your reply to:

Draft