Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
umbraco 4.11.5
here is my Xslt where I make a check on "$currentPage/testBackgroundBillede/widgets/widget/umbracofile" is empty.
if it is not empty then it displays the images.
but if it is empty.
I would like to check on the parent if it has images and if it has then it displays the images
from umbraco.config
empty
<testBackgroundBillede> <widgets> <widget isCollapsed="false"> <umbracofile /> <billedetekst /> </widget> </widgets> </testBackgroundBillede>
the two images in
<testBackgroundBillede> <widgets> <widget isCollapsed="false"> <umbracofile>1096</umbracofile> <billedetekst>test</billedetekst> </widget> </widgets> <widget isCollapsed="false"> <umbracofile>1096</umbracofile> <billedetekst>test</billedetekst> </widget> </widgets> </testBackgroundBillede>
Xslt
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <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"/> <xsl:template match="/"> <xsl:variable name="Billede" select="$currentPage/testBackgroundBillede/widgets/widget/umbracofile"/> <xsl:choose> <xsl:when test="$Billede !=''"> <xsl:for-each select="$currentPage/testBackgroundBillede/widgets/widget"> <xsl:variable name="backgroundbillede" select="umbraco.library:GetMedia(.//umbracofile, false)"/> <xsl:variable name="backgroundbilledetext" select=".//billedetekst"/> <img src="{$backgroundbillede/umbracoFile}" alt="{$backgroundbilledetext}" class="bgM"/> </xsl:for-each> </xsl:when> <xsl:otherwise> /* How do I check whether parent have some images */ </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
Hi Brian,
You should be able to select the image(s) recursively and then just iterate over those - something like this:
<xsl:template match="/"> <!-- Recursively grab the widget nodes that have a file assigned --> <xsl:variable name="Billede" select="$currentPage/ancestor-or-self::*[normalize-space(testBackgroundBillede//umbracofile)][1]/testBackgroundBillede/widgets/widget[normalize-space(umbracofile)]" /> <xsl:for-each select="$Billede"> <!-- In here, you're inside a <widget> element --> <xsl:variable name="backgroundbillede" select="umbraco.library:GetMedia(umbracofile, false())" /> <xsl:variable name="backgroundbilledetext" select="billedetekst" /> <img src="{$backgroundbillede/umbracoFile}" alt="{$backgroundbilledetext}" class="bgM" /> </xsl:for-each> </xsl:template>
/Chriztian
Hi Chriztian
just what I was looking for
if it is not too much to ask would I know if you could cut it out for me
<xsl:variablename="Billede"select="$currentPage/ancestor-or-self::*[normalize-space(testBackgroundBillede//umbracofile)][1]/testBackgroundBillede/widgets/widget[normalize-space(umbracofile)]"/>
thanks in advance
Of course :-) - here goes:
Breaking it up:
<xsl:variable name="Billede" select=" $currentPage /ancestor-or-self:: *[normalize-space(testBackgroundBillede//umbracofile)] [1] /testBackgroundBillede/widgets/widget [normalize-space(umbracofile)] "/>
Here's what the individual lines of the select does:
Hope that helps you understand it better.
For the various axes you can try the XPath Axes Visualizer tool to test them.
The normalize-space() function I've found to be the best way to test for content in an element/attribute.
normalize-space()
thank you so much
/Brian
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Xslt if empty then go to parent
umbraco 4.11.5
here is my Xslt where I make a check on "$currentPage/testBackgroundBillede/widgets/widget/umbracofile" is empty.
if it is not empty then it displays the images.
but if it is empty.
I would like to check on the parent if it has images and if it has then it displays the images
from umbraco.config
empty
the two images in
Xslt
Hi Brian,
You should be able to select the image(s) recursively and then just iterate over those - something like this:
/Chriztian
Hi Chriztian
just what I was looking for
if it is not too much to ask would I know if you could cut it out for me
thanks in advance
Of course :-) - here goes:
Breaking it up:
Here's what the individual lines of the select does:
Hope that helps you understand it better.
For the various axes you can try the XPath Axes Visualizer tool to test them.
The
normalize-space()
function I've found to be the best way to test for content in an element/attribute./Chriztian
Hi Chriztian
thank you so much
/Brian
is working on a reply...