I'm tring to get a picture out via MediaPicker and XSLT... But why does it not work?!
The XML-document is taken from the querystring. Then I get data by <xsl:value-of select="datafield" />. That works perfect.
But when I get to the media-part I get "0" as output. My code is: <xsl:value-of select="umbraco.library:GetMedia(@alias = 'image', 'false')/data [@alias = 'umbracoFile']"/>
Another problem is to get the actual image displayed...
There is one problem with this... for some reason I can't use $currentPage. I not exacly sure why, but I think it has something to do with the fact that I'm desciding witch xml-document to view from the querystring...
If not, then add it - just above/outside the first <xsl:template>.
Not sure what you mean about selecting different XML documents from the querystring. Are you using the XSLT via a macro? If so, then you'll still have access to "currentPage".
Try this XSLT... I have added comments to explain further...
<!-- gets the ID from the QueryString -->
<xsl:variable name="id" select="number(umbraco.library:RequestQueryString('Id'))" />
<!-- gets the XML node for the ID -->
<xsl:variable name="node" select="umbraco.library:GetXmlNodeById($id)" />
<!-- not sure what you are trying to loop through here ... if its child nodes, then use "$node/*[@id]" instead -->
<xsl:for-each select="$node">
<!-- call GetMedia using the 'graf' property alias -->
<xsl:value-of select="umbraco.library:GetMedia(graf, 0)/umbracoFile" />
</xsl:for-each>
I'd want to add a few more checks, to make sure that the $id contains a value... and then that the GetXmlNodeById actually returns a nodeset before I try to loop through it. Again, depending what you want to loop through - guessing its child/sub-nodes?
Why doesn't GetMedia work?!
I'm tring to get a picture out via MediaPicker and XSLT... But why does it not work?!
The XML-document is taken from the querystring. Then I get data by <xsl:value-of select="datafield" />. That works perfect.
But when I get to the media-part I get "0" as output. My code is: <xsl:value-of select="umbraco.library:GetMedia(@alias = 'image', 'false')/data [@alias = 'umbracoFile']"/>
Another problem is to get the actual image displayed...
Can someone help me?
Hello ,
Which version of Umbraco are you using? If you are using 4.0.x, then I wrote a blog post about how to use GetMedia:
http://blog.leekelleher.com/2009/11/30/how-to-use-umbraco-library-getmedia-in-xslt/
If you are using v4.5 - my blog post will still be helpful, but the XML schema is slightly different.
Cheers, Lee.
I'm using 4.5.
I'll read your blog now...
Hi Webspas,
OK, for v4.5 - the new XML schema is to swap out the "node" with the nodeTypeAlias and the "data[@alias]" with the property alias name.
Here's an example - based on the code snippet from my blog post:
Cheers, Lee.
There is one problem with this... for some reason I can't use $currentPage. I not exacly sure why, but I think it has something to do with the fact that I'm desciding witch xml-document to view from the querystring...
Do you have the "currentPage" param in your XSLT?
If not, then add it - just above/outside the first <xsl:template>.
Not sure what you mean about selecting different XML documents from the querystring. Are you using the XSLT via a macro? If so, then you'll still have access to "currentPage".
Cheers, Lee.
Yes I have the currentPage, but I get an error every time I want to use it.
Here is the essentials of the code:
Hi Webspas,
Try this XSLT... I have added comments to explain further...
Cheers, Lee.
Ah... I can see the cleverness in this.
What if... is it possible to do sime kind of "GetXmlNodeByName" insted of Id?
I really appreciate your assistance!
Hi Webspas,
There is a function called GetXmlNodeByXPath - which you could use to do something like this:
Cheers, Lee.
I must be really bad at this, because I just can't get this working! :-(
If I write this
I get "No media is maching '0'" as output.
If I do this
I get error: "System.OverflowException: Value was either too large or too small for an Int32."
Remove the @alias bit, you don't need it in v4.5 (thats for the old XML schema).
Cheers, Lee.
I'm very sorry... but I still get an error..."Value was either too large or too small for an Int32."
Is this in the XSLT editor (in the Umbraco back-office)?
Try this...
Cheers, Lee.
Okay. Now I don't get the error, but there is still no image.
Its pretty much impossible for me to help without seeing any XML data.
Use the following to output the XML and copy-n-paste it on here.
If the XSLT editor shows an error, just click the ignore error checkbox.
- Lee
Got it:
<Image id="1145" version="1accfbfa-ee23-434b-92bf-42efe05d1367" parentID="1117" level="2" writerID="2" nodeType="1032" template="0" sortOrder="2" createDate="2010-07-28T10:31:53" updateDate="2010-07-28T10:31:53" nodeName="Family Ski" urlName="familyski" nodeTypeAlias="Image" path="1,1117,1145"><umbracoFile>/media/452/familieski.jpg</umbracoFile><umbracoWidth>591</umbracoWidth><umbracoHeight>304</umbracoHeight><umbracoBytes>178274</umbracoBytes><umbracoExtension>jpg</umbracoExtension></Image>
Ah, I forgot, you're using v4.5 ... any chance you are going to upgrade to v.4.5.1? There was a minor bug with GetMedia in v4.5.0.
If you don't want to upgrade - you'd be crazy not to! But use the following XSLT:
v4.5. needs to have the /Image part in the XPath. You don't need that bit in v4.5.1.
Cheers, Lee.
Yeaha! I can see the image!
Thank you very much Lee! I would never have found out that there was a bug...
Well now I only have to find out a few other things. But I won't disturb you more.
Thank you again!
No problem, glad that GetMedia is working for you now! :-D
Cheers, Lee.
PS. Don't forget to mark the solution (for others who have the same issue).
is working on a reply...