Copied to clipboard

Flag this post as spam?

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


  • Brad 13 posts 34 karma points
    Apr 30, 2010 @ 17:29
    Brad
    0

    XSLT: Convert MediaID to URL

    I have an XSLT that generates some javaScript for me on the fly.  Currently using a text-string for when it passes in images, but I'd like my users to be able to select an image from the media library and pass that URL instead of having them type it in manually.

    Here's they XSL I'm trying... needless to say, it doesn't work yet:

    This DOES NOT work:
    <xsl:value-of select="umbraco.library:GetMedia(data [@alias='myMediaIDField'])"/>

    This writes the Media ID, which isn't what I need.  I need the URL:
    <xsl:value-of select="data [@alias='myMediaIDField']"/>

    Thanks!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 30, 2010 @ 17:35
    Jan Skovgaard
    0

    Hi Brad

    Have a look at this WIKI entry, which is documenting the usage of the GetMedia extension very thourughly - http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

    I hope this helps you.

    /Jan

  • Brad 13 posts 34 karma points
    Apr 30, 2010 @ 18:30
    Brad
    0

    Thanks for the quick response.  That pointed me in the right direction, but I think the fact that I'm nested in a for-each is what's killing me.

    <xsl:for-each select="$currentPage/descendant::node [string(data [@alias='tickerItemActive']) = '1']">
         <xsl:value-of select="data [@alias='tickerText']"/>
         <xsl:value-of select="data [@alias='tickerImage']"/>
         <xsl:value-of select="umbraco.library:GetMedia(   WHAT GOES HERE??   , 0)/data [@alias = 'umbracoFile']"/>
    </xsl:for-each>

    The tickerImage field contains the MediaID for which I'd like to display the URL.

    Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 30, 2010 @ 18:34
    Jan Skovgaard
    1

    <xsl:value-of select="umbraco.library:GetMedia(data[@alias = 'tickerImage'], 0)/data [@alias = 'umbracoFile']"/> - this should do the trick.

    /Jan

  • Brad 13 posts 34 karma points
    Apr 30, 2010 @ 19:14
    Brad
    0

    Unfortunately, that's where I started.  I get an XSL validation error using that code.  Unfortunately, no usable data in it.

    (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(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, Boolean closeWriter)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter 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)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 30, 2010 @ 19:38
    Jan Skovgaard
    0

    Have you tried to see if it's working if you check "skip error testing" ?

    /Jan

  • Brad 13 posts 34 karma points
    Apr 30, 2010 @ 19:39
    Brad
    0

    Yes.  Same result on the client side.  Says, "Error parsing XSLT file" instead of rendering the content.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 30, 2010 @ 19:46
    Tom Fulton
    0

    Try wrapping an if statement around the GetMedia line to ensure there is data there.  I've had this issue before and this fixes it for me, although I don't know the exact reason.

    ie:

    <xsl:for-each select="$currentPage/descendant::node [string(data [@alias='tickerItemActive']) = '1']">
         <xsl:value-of select="data [@alias='tickerText']"/>
         <xsl:value-of select="data [@alias='tickerImage']"/>
         <xsl:if test="data[@alias = 'tickerImage'] != ''">
           <xsl:value-of select="umbraco.library:GetMedia(data[@alias = 'tickerImage'], 0)/data [@alias = 'umbracoFile']"/>
         </xsl:if>
    </xsl:for-each>
  • Brad 13 posts 34 karma points
    Apr 30, 2010 @ 21:29
    Brad
    0

    No such luck.  With the <xsl:if> added the XSLT still won't save unless the verification box is unchecked.  Still results in an error client-side, though.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 30, 2010 @ 21:42
    Tom Fulton
    0

    Hmm..interesting.  I pasted your the exact code above and changed the field names, and it saves & works fine here.  However it gets the error you mention if I don't include the IF statement.  Can't think of anything else...

  • Brad 13 posts 34 karma points
    Apr 30, 2010 @ 21:55
    Brad
    0

    Guys, thanks for the help.

    I have no idea what was wrong.  I modified the variable names before posting to protect a client's confidentiality (their company name was part of the variable name.)  Their name happens to contain a couple uppercase letters together.  Made them all lowercase in the alias and everything now works.

    Wow....  did not expect that.

    Thanks again.  Knowing it worked on your machine, Tom, is what tipped me off.  Probably never would have tried new variable names otherwise.

Please Sign in or register to post replies

Write your reply to:

Draft