Copied to clipboard

Flag this post as spam?

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


  • North Krimsly 59 posts 80 karma points
    Sep 21, 2010 @ 19:09
    North Krimsly
    0

    New 4.5 schema - using umbraco.library:GetMedia for a slideshow

    Greetings all,

    I'm having trouble with understanding the new schema for 4.5. I'd like to write an xslt script that does the following:

    Document Type: Slideshow

    Document Type: Slideshow Item (child document type of Slideshow). This document type has a field "slideshowItem" which is of type MediaPicker.

    There will be several Slideshow Items which are child documents of Slideshow, each with its own media image. I'd like the xslt to traverse through every child item of Slideshow and output the image in the Slideshow item using umbraco.library:GetMedia. Can someone please suggest some ways to do this?  I  had this working in the 4.0 schema but I just don't understand the 4.5 schema well enough.

    Also if you have suggestions on how to debug xslt scripts, that would be very helpful.  Basically when I write a script wrong, I get nothing output which makes it difficult to trouble-shoot what I did wrong.

    Thanks a lot,

    -NorthK

  • Kim Andersen 1447 posts 2197 karma points MVP
    Sep 21, 2010 @ 19:44
    Kim Andersen
    0

    Hi North

    Could you provide us with the xslt that you had working with the old XML schema in v4.0. Then we can rewrite that code.

    And another small question - Are you running v4.5 or v4.5.1/4.5.2? I ask because there's a small change in the XML in v4.5 and v4.5.X :)

    /Kim A

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 21, 2010 @ 19:53
    Dennis Aaen
    0

    Hello NorthK,

    I'm also relatively new to umbraco environment, but therefore I would like to try to help you,

    My guess would be that you could print all the children out from under the document type slideshow so.

    <xsl:for-each select="./child::*[@isDoc and self::slideshow]">
    <li>
    <xsl:if test="$currentPage/your Media picker alias !=''">
    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/your Media picker alias , 0)" />
    <xsl:variable name="alt" select="umbraco.library:GetMedia($currentPage/your Media picker alias , 0)/@nodeName" />
    <img src="{$media/umbracoFile}" alt="{$alt}"/>
    </xsl:if>
    </li>
    </xsl:for-each>


    But as I said, I am fairly new, so if I am wrong, I hope you can bear with me.

    The way I used to debug my scripts by typing my variables out to see if they get the right value, or use the visualization button in Umbraco, to see if I get hold of the right data when I think I've written the right script

    Hope it can help you.

    / Dennis

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Sep 21, 2010 @ 22:10
    Chriztian Steinmeier
    0

    Hi NorthK,

    This is my take, using the match templates approach (change Document Type names if necessary):

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="umbraco.library"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
        <!-- You should be more specific here - but "//" will find all SlideShow documents -->
        <xsl:variable name="slideShowNode" select="$siteRoot//SlideShow" />
    
        <xsl:template match="/">
            <xsl:apply-templates select="$slideShowNode" />           
        </xsl:template>
    
        <!-- Template for SlideShow document -->
        <xsl:template match="SlideShow">
            <div class="slideshow">
                <!-- Render all SlideShow Items that have an id in the slideshowitem property -->
                <xsl:apply-templates select="SlideShow_Item[number(slideshowitem)]" />
            </div>
        </xsl:template>
    
        <xsl:template match="SlideShow_Item">
            <!-- Grab the mediaNode (if using 4.5.0 use the second instead)-->
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(slideshowitem, false())" />
            <!-- <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(slideshowitem, false())/Image" /> -->
    
            <!-- Render the image -->
            <img src="{$mediaNode/umbracoFile}" width="{$mediaNode/umbracoWidth}" height="{$mediaNode/umbracoHeight}" alt="[image]" />
        </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian

  • North Krimsly 59 posts 80 karma points
    Sep 22, 2010 @ 00:18
    North Krimsly
    0

    All,

    Here is the (simplified) code I had working under 4.0.x.  I am running 4.5.2 at this time.  Thanks a lot for your responses, and please let me know if this sample code changes how you would suggest coding the solution.  I'm also still wondering what your approach is for debugging these xslt scripts!

    Thanks again,

    -NorthK

    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
                <img src="{umbraco.library:GetMedia(data[@alias='portfolioItemMainImage'], false)/data[@alias='umbracoFile']}" alt="work sample" />
    </xsl:for-each>
    </xsl:template>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Sep 22, 2010 @ 00:27
    Chriztian Steinmeier
    1

    The translation of that snippet would be:

    <xsl:param name="currentPage"/>
    <xsl:template match="/">
        <xsl:for-each select="$currentPage/*[not(umbracoNaviHide = 1)]">
            <img src="{umbraco.library:GetMedia(portfolioItemMainImage, false())/umbracoFile}" alt="work sample" />
        </xsl:for-each>
    </xsl:template>

    For debugging I use the XMLDump (duh - wrote it for that :-) package, or the "debug textarea copy-of trick":

    <textarea cols="60" rows="12"><xsl:copy-of select="$currentPage" /></textarea> 

    /Chriztian

  • North Krimsly 59 posts 80 karma points
    Sep 22, 2010 @ 01:27
    North Krimsly
    0

    Chriztian,

    When I tried code similar to your translated snippet, I get an xslt save error "System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)". My code looks like:

      <xsl:template match="/">
        <xsl:for-each select="$currentPage/*[not(umbracoNaviHide = 1)]">
               <img src="{umbraco.library:GetMedia(slideshowItem, false())/umbracoFile}" alt="work sample" />
        </xsl:for-each>

    Any ideas?  Thanks a lot,

    -NorthK

  • Kim Andersen 1447 posts 2197 karma points MVP
    Sep 22, 2010 @ 08:27
    Kim Andersen
    0

    North,

    could you try making a check to see if the current node contains an image like this:

    <xsl:for-each select="$currentPage/*[not(umbracoNaviHide = 1)]">
    <xsl:if test="./
    slideshowItem != ''">
               <img src="{umbraco.library:GetMedia(slideshowItem, false())/umbracoFile}" alt="work sample" />
    </xsl:if>
    </xsl:for-each>

    /Kim A

  • North Krimsly 59 posts 80 karma points
    Sep 22, 2010 @ 22:50
    North Krimsly
    0

    Hello again all,

    For some reason, the following very simple xslt doesn't display any results (meaning no nodes are matched).  I've set up the document types as I noted in the first post in this thread, and I have some content published (one node of type slideshow and two child nodes under that of type slideshowItem).  I've modeled this code after the example at http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/xslt-examples-updated-to-new-schema. Does anyone know what is happening?

    Thanks,

    -NorthK

      <xsl:param name="currentPage"/>
        <xsl:template match="/">
        <xsl:for-each select="$currentPage/slideshowItem[@isDoc]">
           <p>inside loop</p>
        </xsl:for-each>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Sep 22, 2010 @ 23:02
    Chriztian Steinmeier
    0

    Hi NorthK,

    Are your Document Types named "slideshow" and "slideshowItem" ?

    The way you describe it in the first post, I'd assume your doctypes were named "Slideshow" and "Slideshow_Item" (based on the names you gave) - and then the property on Slideshow_Item documents would have the name "slideshowItem" - is that correct?

    XML (and thus XSLT) is case-sensitive so it's important to get these right - my first code example uses "SlideShow" instead of "Slideshow" so that wouldn't work - have you tried that piece of code with your exact names?

    Otherwise, try the textarea-debug method:

    <textarea><xsl:copy-of select="$currentPage/ancestor-or-self::root" /></textarea>

    - and post some of it here so we can see the exact setup

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft