I do have two parameters to the GetMedia call. My Typo was because I accidentally deleted the , between the two parameters. i have a zro as the second parameter.
Anyway, adding the xsl:if around the whold img-tag solved part of the issue. It seems that it is the code I have to populate the imageID variable that is failing. The code I posted in my first thread was shortened for clarity... stupid Jan... Anyway, the code I have for populating the variable is actually this:
And it seems that if the picture is empty, then the value of the variable is NOT set to 1121. That is why the stuff fails, because the empty string is a bad parameter for GetMedia :-)
But why isn't 1121 set as the value of the imageID variable? 1121 is the image I want to display if no image has been set on the member.
Nope, you don't need to specify the dot operator in the for each loop, altho it helps understanding you're currently working/getting info from the current node being iterated.
GetMedia
Hi all.
I have an XSLT script, where I want to list all members. I have attahed an image to all members, which is a Media Picker type.
So in my XSLT I want to generate an img tag to show the image. My code goes something like this:
<xsl:variable name="members" select="eliasen:GetAllMembers()" />
<xsl:for-each select="$members/node">
<xsl:variable name="imageID"><xsl:value-of select="data[@alias='picture']" /></xsl:variable>
<img>
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia($imageID0)/data [@alias = 'umbracoFile']" />
</xsl:attribute>
</img>
</xsl:for-each>
I am outputting other stuff as well,
My issue is that when I save this XSLT I get this error:
(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)
If i change $imageID to 1121 (hardcoding an ID for a image) then the save goes well.
So what might be the issue?
Thanks in advance!
--
eliasen
In the sample you provided, it says "imageID0" (with a zero at the end..). Might that be your problem?
Hi,
this is because when you save the xslt, it does not know on which page you are, so the variable imageID does not get filled.
Nothing to worry about. You can solve this by adding something like this:
It should save without errors then.
Alternatively, you could check the 'skip error-testing' and save the file (if you are sure it works ok)
HTH,
Peter
Hi all
My code is umbraco.library:GetMedia($imageID) and not umbraco.library:GetMedia($imageID0) which I accidentally copied...
Sebastian, the typo is only in this post - not in the code
Peter, if I skip testing of the XSLT and thereby force the save, I get an XSLT parse error at runtime.
So the error was caused by this typo or do you still have the problem even though the typo has been corrected?
/Jan
Jan, Peters point is that you need to add the surrounding if-statement (using the right var-name)
>Tommy
Ah, you were faster to post than me. Never mind me then :-)
/Jan
aah - my post was outdated I see. Sorry.
The method takes two parameters:
umbraco.library:GetMedia($imageID, 0)
The last one is a boolean deciding if you want sub-media (from a folder) or just the one media item.
Great spotted Morten. Jan, try this:
</xsl:if>
Actually, I'm not sure you can use the false keyword anymore. Think it only works with 0 and 1. Somtehing about compiled XSLTs...
Hi all
I do have two parameters to the GetMedia call. My Typo was because I accidentally deleted the , between the two parameters. i have a zro as the second parameter.
Anyway, adding the xsl:if around the whold img-tag solved part of the issue. It seems that it is the code I have to populate the imageID variable that is failing. The code I posted in my first thread was shortened for clarity... stupid Jan... Anyway, the code I have for populating the variable is actually this:
<xsl:variable name="imageID">
<xsl:choose>
<xsl:when test="data[@alias='picture'] = ''">1121</xsl:when>
<xsl:otherwise><xsl:value-of select="data[@alias='picture']" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
And it seems that if the picture is empty, then the value of the variable is NOT set to 1121. That is why the stuff fails, because the empty string is a bad parameter for GetMedia :-)
But why isn't 1121 set as the value of the imageID variable? 1121 is the image I want to display if no image has been set on the member.
Thanks.
@Morton: you can use false in the function as a string: 'false'
It works for me without problems.
Thomas
Hi Jan
Try writing this
I'm quite sure you need to use the string-length function to find out if the property contains anything.
/Jan
Hi all
This works instead:
<xsl:variable name="imageID">
<xsl:choose>
<xsl:when test="data[@alias='picture'] != ''"><xsl:value-of select="data[@alias='picture']" /></xsl:when>
<xsl:otherwise>1121</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Basically, I just switched what was he "when" and what was the "otherwise" I am very puzzled that this should matter at all.
Thank you to all who answered. I am very impressed that so may people helped SO fast...
You also can test of the string itself:
hth, Thomas
Glad it works now! There are a lot of people around here trying to help out others. That's what you have to love about umbraco :)
It's always good to see people asking questions and in the end solving their own problem. Still confused why your earlier approach didn't work though.
And for future reference, post your complete code in your initial question, otherwise it might get even more confusing like it did here ;)
There is a " missing at the end of the test attribute...
Also not important therefore that you found a solution...
Cheers, Thomas
<xsl:variable name="members" select="eliasen:GetAllMembers()" />
<xsl:for-each select="$members/node">
<xsl:variable name="imageID"><xsl:value-of select="data[@alias='picture']" /></xsl:variable>
should this not read:
<xsl:variable name="members" select="eliasen:GetAllMembers()" />
<xsl:for-each select="$members/node">
<xsl:variable name="imageID"><xsl:value-of select="./data[@alias='picture']" /></xsl:variable>
the ./ telling it that you are using the current node in the for-each list?
Nope, you don't need to specify the dot operator in the for each loop, altho it helps understanding you're currently working/getting info from the current node being iterated.
Cheers,
/dirk
is working on a reply...