Copied to clipboard

Flag this post as spam?

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


  • Steve Barnhouse 40 posts 63 karma points
    Aug 05, 2010 @ 20:22
    Steve Barnhouse
    0

    Need xslt help getting the path of an image file

    I'm using Umbraco 4.5.1.  I'm trying to display an image as explained on Umbraco.tv in the Using Content and Media Pickers video.

    When I visualize this xslt statement:

    <xsl:copy-of select="umbraco.library:GetMedia($currentPage/newsImage, 'false')" />

    I get this: /media/168/hydrangeas.jpg1024768595284jpg  

    And when I decode it it I get this:

    <img id="1071" version="85346fbe-60ae-46cb-a334-2c4c17508777" parentid="-1" level="1" writerid="0" nodetype="1032" template="0" sortorder="48" createdate="2010-08-04T18:20:40" updatedate="2010-08-04T18:20:40" nodename="Flowers" urlname="flowers" writername="Administrator" nodetypealias="Image" path="-1,1071"><umbracofile>/media/168/hydrangeas.jpg</umbracofile><umbracowidth>1024</umbracowidth><umbracoheight>768</umbracoheight><umbracobytes>595284</umbracobytes><umbracoextension>jpg</umbracoextension>

    Now how do I get the path of the image?

    As suggested in the video, I tried this:

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/newsImage, 'false')/data [@alias = 'umbracofile']" />

    And the code in the Business Website Starter Package suggests this:

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/newsImage, 'false')/Image/umbracofile" />

    But they yield a message saying the xslt didn't generate any output.

    Help!

  • Kim Andersen 1447 posts 2197 karma points MVP
    Aug 05, 2010 @ 20:37
    Kim Andersen
    0

    Hi there Steve

    In v4.5 the last statement you tried should work(with an uppercase F in umbracoFile), but the XML has been changed a bit from 4.5 to 4.5.1 so in 4.5.1 you can probably get the path to the image like this:

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/newsImage, 'false')/umbracoFile" />

    The only thing that has changed is the <Image>-tag in the XML. Hope the above snippet works for you :)

    /Kim A

  • Steve Barnhouse 40 posts 63 karma points
    Aug 05, 2010 @ 21:17
    Steve Barnhouse
    0

    Kim,

    Thanks for the prompt response!  Yes, the snippet you provided works.

    Question:  where can I find this kind of information?  

    --steve

  • Kim Andersen 1447 posts 2197 karma points MVP
    Aug 05, 2010 @ 21:34
    Kim Andersen
    0

    An approach I often use is to find out how my XML looks like. This is a good starting point.

    In your case you could try printing out the XML returned by the GetMedia-extension. Like this:

    <textarea>
    <xsl:copy-of select="umbraco.library:GetMedia($currentPage/newsImage, 'false')"/>
    </textarea>

    I use this method every time I'm in doubt about the XML I work with in the current context. Another example is to make sure a given property is represented on the current page. Then you'll just write out the $currentPage variable like this:

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

    /Kim A

  • Steve Barnhouse 40 posts 63 karma points
    Aug 05, 2010 @ 23:35
    Steve Barnhouse
    0

    Kim,

    Thanks for the helpful suggestions.

    However, I'm still kind of in the dark.  The XML that the GetMedia extension returns contains this:

    <umbracofile>/media/168/hydrangeas.jpg</umbracofile>

    But I need to use /umbracoFile with an uppercase 'F' in my xslt.  Where is this documented?  

    As a beginner, I feel like I'm spending a lot of time just guessing.  

    But I do appreciate the enthusiasm and helpfulness of the user community, so thanks!


  • Kim Andersen 1447 posts 2197 karma points MVP
    Aug 06, 2010 @ 08:49
    Kim Andersen
    0

    Hi again Steve.

    Try printing GetMedia out without the umbracoFile at the end.

    I just tried this on a fresh install of umbraco 4.5.1 and i got the following XML returnerd:

    <Image id="1064" version="afcd5654-f0b4-40a4-ab98-f9d3c5616a3f" parentID="-1" level="1" writerID="0" nodeType="1032" template="0" sortOrder="44" createDate="2010-08-06T08:35:04" updateDate="2010-08-06T08:36:17" nodeName="test" urlName="test" writerName="Administrator" nodeTypeAlias="Image" path="-1,1064">
    <umbracoFile>/media/185/image.jpg</umbracoFile>
    <umbracoWidth>800</umbracoWidth>
    <umbracoHeight>600</umbracoHeight>
    <umbracoBytes>90686</umbracoBytes>
    <umbracoExtension>jpg</umbracoExtension>
    </Image>

    As you can see this is the XML returned by the GetMedia extension. In here you have the umbracoFile, umbracoWidth etc. I printed it out like this:

    <textarea>
       
    <xsl:copy-of select="umbraco.library:GetMedia($currentPage/mainImage, 'false')"/>
    </textarea>

    mainImage is just the alias I used where yours are called newsImage. Does that make more sense now?

    In the beginning it can be a little difficult to just guess, and therefore it's always a good idea to see the XML instead of just shooting in the dark.

    By the way there's written a couple of Wiki entries about the new XML schema. Eg.: http://our.umbraco.org/wiki/reference/xslt/45-xml-schema and http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/xslt-examples-updated-to-new-schema

    I hope this explanation made a bit more sense to you Steve :)

    /Kim A

  • Steve Barnhouse 40 posts 63 karma points
    Aug 07, 2010 @ 00:52
    Steve Barnhouse
    0

    Hi Kim,

    Yes, that helps.  Thanks.  And thanks for the links.

    When I used the visualizer tool in the xsl editor, and decoded the result, it showed the nodes in all lower case (as shown in my first post on this topic), but when I put it in a <textarea> it showed the nodes in mixed case.  Also, using the <textarea> caused an xslt error for some reason, but it seemed OK to ignore the error.

    By the way, how did you get your <textarea> output so nicely formated?  When I tried it, it was all on one line with no syntax highlighting.

    Thanks again!

    --steve


     

  • Kim Andersen 1447 posts 2197 karma points MVP
    Aug 07, 2010 @ 15:36
    Kim Andersen
    0

    Everytime I use this method, I'll grab all of the content from the textarea, and paste it into Visual Studio in a dummy.xml-file. Then Visual Studio formats the XML nicely which of course makes it a lot more readable. If you just get a single line of code inside of Visual Studio as well, try pressing Ctrl+k+d (or go to Edit-->Format Document).

    If you don't have Visual Studio installed, you can just use your favorite editor like Notepad++, Dreamweaver etc.

    /Kim A

  • sun 403 posts 395 karma points
    Aug 07, 2010 @ 18:26
    sun
    0

    I always see the database of umbraco to find out xml structure.

  • Kim Andersen 1447 posts 2197 karma points MVP
    Aug 07, 2010 @ 18:36
    Kim Andersen
    0

    Sun, isn't it to much work to go to into the database just to see the XML? Are you using it to see the current page or are you only using this method when you want to see all the XML found in the whole tree?

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft