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']"/>
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.
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.
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...
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.
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!
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
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
<xsl:value-of select="umbraco.library:GetMedia(data[@alias = 'tickerImage'], 0)/data [@alias = 'umbracoFile']"/> - this should do the trick.
/Jan
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)
Have you tried to see if it's working if you check "skip error testing" ?
/Jan
Yes. Same result on the client side. Says, "Error parsing XSLT file" instead of rendering the content.
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:
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.
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...
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.
is working on a reply...