Do you have to use > still in the new schema for something like:
<xsl:if test="count($images/node) > 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 > vs > is something I see in other comparisons between new and old schema code is why I'm wondering if that's the problem.
<!-- 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 > 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) > 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>
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(.)
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.
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) > 0">
<!-- Better - no need to count anything: -->
<xsl:if test="$images/node">
> vs > in new schema
Do you have to use > still in the new schema for something like:
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 > 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
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
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
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:
/Chriztian
Chriztian, thats awesome, thanks for taking the time to explain that.
-Amir
is working on a reply...