Copied to clipboard

Flag this post as spam?

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


  • Jan Eliasen 5 posts 36 karma points
    Aug 05, 2009 @ 21:13
    Jan Eliasen
    0

    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

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Aug 05, 2009 @ 21:14
    Sebastiaan Janssen
    1

    In the sample you provided, it says "imageID0" (with a zero at the end..). Might that be your problem?

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 05, 2009 @ 21:16
    Peter Dijksterhuis
    100

    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:

    <xsl:if test="$imageID != '' ">
     <img>
        <xsl:attribute name="src">
          <xsl:value-of select="umbraco.library:GetMedia($imageID0)/data [@alias = 'umbracoFile']" />
        </xsl:attribute>
      </img>
    </xsl:if>

    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

  • Jan Eliasen 5 posts 36 karma points
    Aug 05, 2009 @ 21:19
    Jan Eliasen
    0

    Hi all

    My code is umbraco.library:GetMedia($imageID) and not umbraco.library:GetMedia($imageID0) which I accidentally copied...

     

  • Jan Eliasen 5 posts 36 karma points
    Aug 05, 2009 @ 21:21
    Jan Eliasen
    0

    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.

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Aug 05, 2009 @ 21:21
    Jan Skovgaard
    0

    So the error was caused by this typo or do you still have the problem even though the typo has been corrected?

    /Jan

  • Tommy Poulsen 514 posts 708 karma points
    Aug 05, 2009 @ 21:21
    Tommy Poulsen
    0

    Jan, Peters point is that you need to add the surrounding if-statement (using the right var-name)

    >Tommy

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Aug 05, 2009 @ 21:22
    Jan Skovgaard
    0

    Ah, you were faster to post than me. Never mind me then :-)

    /Jan

  • Tommy Poulsen 514 posts 708 karma points
    Aug 05, 2009 @ 21:22
    Tommy Poulsen
    0

    aah - my post was outdated I see. Sorry.

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 05, 2009 @ 21:25
    Morten Bock
    0

    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.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 05, 2009 @ 21:28
    Peter Dijksterhuis
    0

    Great spotted Morten. Jan, try this:

    <xsl:if test="$imageID != '' ">
     <img>
        <xsl:attribute name="src">
          <xsl:value-of select="umbraco.library:GetMedia($imageID, false)/data [@alias = 'umbracoFile']" />
        </xsl:attribute>
      </img>
    </xsl:if>

     

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 05, 2009 @ 21:36
    Morten Bock
    0

    Actually, I'm not sure you can use the false keyword anymore. Think it only works with 0 and 1. Somtehing about compiled XSLTs...

  • Jan Eliasen 5 posts 36 karma points
    Aug 05, 2009 @ 21:40
    Jan Eliasen
    0

    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.

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 05, 2009 @ 21:46
    Thomas Höhler
    0

    @Morton: you can use false in the function as a string: 'false'

    It works for me without problems.

    Thomas

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Aug 05, 2009 @ 21:47
    Jan Skovgaard
    0

    Hi Jan

    Try writing this

     

    <xsl:variable name="imageID">
              <xsl:choose>
               <xsl:when test="string-length(data[@alias='picture']) = ''>1121</xsl:when>
               <xsl:otherwise><xsl:value-of select="data[@alias='picture']" /></xsl:otherwise>
              </xsl:choose>
             </xsl:variable>

    I'm quite sure you need to use the string-length function to find out if the property contains anything.

     

    /Jan

  • Jan Eliasen 5 posts 36 karma points
    Aug 05, 2009 @ 21:48
    Jan Eliasen
    1

    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...

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 05, 2009 @ 21:51
    Thomas Höhler
    0

    You also can test of the string itself:

    <xsl:variable name="imageID">
     
    <xsl:choose>
       
    <xsl:when test="string(data[@alias='picture']) != ''><xsl:value-of select="data[@alias='picture']" />
    </xsl:when>
     
    <xsl:otherwise>1121</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    hth, Thomas

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Aug 05, 2009 @ 21:53
    Peter Dijksterhuis
    0

    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 ;)

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 05, 2009 @ 21:54
    Thomas Höhler
    0

    There is a " missing at the end of the test attribute...

    Also not important therefore that you found a solution...

    Cheers, Thomas

  • Steve D 11 posts 41 karma points
    Aug 17, 2009 @ 16:56
    Steve D
    0

    <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?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 17, 2009 @ 17:56
    Dirk De Grave
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft