Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1287 posts 2744 karma points
    Mar 29, 2011 @ 18:27
    Amir Khan
    0

    > vs > in new schema

    Do you have to use > still in the new schema for something like:

    <xsl:if test="count($images/node) &gt; 0">

    I'm updating some code that loops through a media folder and puts the images inside into a list and am getting nothing returned. I used the XSLT Updater package and it only changed a couple references to things like:

    $currentPage/data[@alias='rotatingImageFolder']

    The difference between teh &gt; vs > is something I see in other comparisons between new and old schema code is why I'm wondering if that's the problem.

    Here's the full code below if it helps.

    Thanks!

    Amir

    <?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"
    exclude-result-prefixes="msxml umbraco.library">


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

    <xsl:param name="currentPage"/>

    <!-- MAIN TEMPLATE -->
    <xsl:template match="/">

    <!-- Variable with the selected media folder ID -->
    <xsl:variable name="mediaFolderID" select="$currentPage/rotatingImageFolder"/>

    <!-- Call template generates the HTML for the images-->
    <xsl:call-template name="LoopThroughImagesInFolder">
    <xsl:with-param name="mediaFolderID">
    <xsl:value-of select="$mediaFolderID"/>
    </xsl:with-param>
    </xsl:call-template>

    </xsl:template>

    <!-- LOOP THROUGH IMAGES IN FOLDER TEMPLATE -->
    <xsl:template name="LoopThroughImagesInFolder">
    <!-- Parameter with a media folder ID -->
    <xsl:param name="mediaFolderID"/>

    <!-- Check that you really have an ID -->
    <!-- Without this test the script can fail -->
    <xsl:if test="$mediaFolderID &gt; 0">

    <!-- Get the media node using the ID -->
    <xsl:variable name="images" select="umbraco.library:GetMedia($mediaFolderID, 1)" />

    <!-- Check if the folder contains any child nodes -->
    <xsl:if test="count($images/node) &gt; 0">
    <div id="slider">
    <ul>

    <!-- Start iterating the child nodes -->
    <xsl:for-each select="$images/node">

    <xsl:choose>
    <!-- Is it an image?
    Please note that this only works if your images have the
    @nodeTypeAlias "Image". If you have called it something else,
    you need to replace the name.
    -->
    <xsl:when test="string(./@nodeTypeAlias) = 'Image'">
    <!-- Print the image code -->
    <li>
    <img>
    <xsl:attribute name="src">
    <xsl:value-of select="./umbracoFile"/>
    </xsl:attribute>
    </img>
    </li>
    </xsl:when>
    <!-- Is it a folder?
    Please note that this only works if your media folders have the
    @nodeTypeAlias "Folder". If you have called it something else,
    you need to replace the name.
    -->
    <xsl:when test="string(./@nodeTypeAlias) = 'Folder'">
    <!--
    Make a recursive call to myself with the ID of
    the current node in the iteration
    -->
    <xsl:call-template name="LoopThroughImagesInFolder">
    <xsl:with-param name="mediaFolderID">
    <xsl:value-of select="./@id"/>
    </xsl:with-param>
    </xsl:call-template>
    </xsl:when>
    </xsl:choose>
    </xsl:for-each>

    </ul>
    </div>
    </xsl:if>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>


     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 29, 2011 @ 18:46
    Tom Fulton
    0

    I think you need to replace $images/node with $images/Image or whatever your media type alias is (or $images/* if you aren't sure of the type).  I see this in two places

    Also, I'm not sure @nodeTypeAlias will work, you might need to change that to local-name(.)

    -Tom

  • Amir Khan 1287 posts 2744 karma points
    Mar 29, 2011 @ 18:56
    Amir Khan
    0

    Tom,

    That's exactly what it was. $images/Image and $images/* both worked. I didn't realize that the media type alias was in Settings > Media Types > Image > Alias for some reason, athough I had seen it referred to in other posts.


    Thanks a ton for your help!

    -Amir

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 30, 2011 @ 23:23
    Chriztian Steinmeier
    3

    Hi Amir,

    Just to answer the question regarding the greater-than character:

    It's not strictly required to escape greater-than characters - only ampersands (&) and less-than characters must always be escaped inside attribute values - this is an XML conformance rule, not something Umbraco decides, so doesn't matter which Umbraco XML Schema is used.

    BTW: Tests like that could actually be written without the counting and comparing because a test will be silently wrapped in a call to boolean() and if the $images/node selection doesn't contain any nodes, the test will return false:

    <!-- Works: -->
    <xsl:if test="count($images/node) &gt; 0">
    
    <!-- Better - no need to count anything: -->
    <xsl:if test="$images/node">

    /Chriztian

     

  • Amir Khan 1287 posts 2744 karma points
    Mar 31, 2011 @ 22:37
    Amir Khan
    0

    Chriztian, thats awesome, thanks for taking the time to explain that.

     

    -Amir

Please Sign in or register to post replies

Write your reply to:

Draft