Copied to clipboard

Flag this post as spam?

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


  • Zagros 12 posts 32 karma points
    Dec 18, 2010 @ 22:31
    Zagros
    0

    using xslt and getMedia to get file path of a media picker image

    hi,

    I have a content type that has a title and a thumbnail.  Title is text, and thumbnail is a media picker. Using the xslt above, I can get an unordered list of title and thumbnail (which are numeric id's) printed to the screen.  The third value-of call that uses the GetMedia doesn't work for me.  It's always blank.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes" />

    <xsl:param name="currentPage"/>

    <!-- Don't change this, but add a 'contentPicker' element to -->
    <!-- your macro with an alias named 'source' -->
    <xsl:variable name="source" select="/macro/source"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '-1']">
    <li>
    <span>
    <xsl:value-of select="./title"/> -
    <xsl:value-of select="./thumbnail"/> -
    <xsl:value-of select="umbraco.library:GetMedia(./thumbnail,0)/data [@alias='umbracoFile']" />
    </span>
    </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>

    can someone please help? when ./title and ./thumbnail both print the title and media id, shouldn't the getMedia call get the file path of the image as well?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 18, 2010 @ 23:01
    Kim Andersen
    0

    Hi Zagros

    You need to change this line:

    <xsl:value-of select="umbraco.library:GetMedia(./thumbnail,0)/data [@alias='umbracoFile']" />

    to this:

    <xsl:value-of select="umbraco.library:GetMedia(./thumbnail,0)/umbracoFile" />

    this should give you the path to the image printet to the screen. You had used some XSLT code that only worked with the legacy schema.

    Besides that, you should probably check to see if the thumbnail-property is empty or not, to prevent the GetMedia extension of generating an error :)

    /Kim A

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 18, 2010 @ 23:01
    Jan Skovgaard
    0

    Hi Zagros

    It's probably because you're mixing the two XML schemas :-)

    In the following you use the old data[@alias='umbracoFile'] syntax

          <xsl:value-of select="umbraco.library:GetMedia(./thumbnail,0)/data [@alias='umbracoFile']" />

    With the new schema it should read this

    <xsl:value-of select="umbraco.library:GetMedia(./thumbnail,0)/umbracoFile" />

    Hope this helps.

    /Jan

  • Zagros 12 posts 32 karma points
    Dec 18, 2010 @ 23:02
    Zagros
    0

    where was this info??....

     

    to be honest i just came back to say I tried it knowing xslt and came to post the solution and saw your reply...

     

     

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 18, 2010 @ 23:06
    Jan Skovgaard
    0

    Hi Zagros

    Just happy you found the solution to your problem.

    It's a comon mistake to mix the two schemas since there are many samples based on the legacy schema out there and sometimes one forgets to amend them to use the new schema.

    /Jan

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 18, 2010 @ 23:09
    Kim Andersen
    1

    Zagros, if you want to see some examples of the new XML schema you can take a look in the Wiki here. The XML schema changed in v4.5, and in v4.5.1 the schema for media items changed a bit again. But you haven't quite got the grab of the new schema, I'd suggest that you try to print out the XML in a textarea like this:

    <textarea>
    <xsl:copy-of select="$currentPage" />
    </textarea>

    if you want to see the XML of the current page.

    You can check out the returned XML from the GetMedia extension like this:

    <textarea>
    <xsl:copy-of select="umbraco.library:GetMedia(./thumbnail,0)" />
    </textarea>

    /Kim A

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 18, 2010 @ 23:13
    Jan Skovgaard
    0

    ...And if one is a bit lazy the XML dump package http://our.umbraco.org/projects/developer-tools/xml-dump is another great option to see the XML structure.

    /Jan

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 18, 2010 @ 23:31
    Kim Andersen
    0

    By the way Zagros. I guess that you don't want to iterate through the nodes that has the umbracoNaviHide property checked, right?

    Then you need to change the for-each to this:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">

    The only thing that I've changed is that -1 should be 1. When a true/false data type is checked, it's set to 1 and otherwise it's set to 0. Just a small thing, but I just wanted to let you know :)

    /Kim A

  • Zagros 12 posts 32 karma points
    Dec 18, 2010 @ 23:48
    Zagros
    0

    thanks good catch,

    I forgot to change that back after experimenting

     

Please Sign in or register to post replies

Write your reply to:

Draft