I am looping through the children of the current node, and when I find a node which itself has children, I need to loop through those and show an image which is a property of that child page. Page structure is as follows:
The field in question is slideImage. The children of the current page might have just an articlePhoto, and when they do, this displays fine; however, some child pages might have a slideShow, which involves the currentPage having child nodes which themselves have a media picker property called a slideImage.
The result I am getting here is all 3 slideImages for the first page in the nested loop, and none for the rest (??). What I want here is to display the First slideImage of each of the children in the nested loop. Haven't got to the first-only issue just because my loop structure seems to be wrong in the first place. What am I missing?
Thanks Chiztian -- this code is great and will save a lot of time elsewhere!! One thing, though -- under Category, there are Document Types other than Product (I'm trying to use the same template on multiple pages) -- so I copied theProduct one:
<!-- Template for a single Product --> <xsl:template match="Industry">
<div style="width:100%;height:100%;clear:both;padding:20px 0px 20px 0px;"> <!-- Process articlePhoto if present --> <xsl:apply-templates select="articlePhoto[normalize-space()]" /> <!-- Process the 1st Slide child that have a slideImage --> <xsl:apply-templates select="Slide[normalize-space(slideImage)][1]" /> <h1 style="font-size:2em;padding-bottom:10px;display:inline;">
<a href="{umbraco.library:NiceUrl(@id)}"> <!-- Take abstractTitle but fallback to @nodeName if empty --> <xsl:value-of select="(@nodeName[not(normalize-space(../abstractTitle))] | abstractTitle)[1]" /> </a> </h1> <xsl:choose> <xsl:when test="normalize-space(abstractText)"> <xsl:value-of select="abstractText" disable-output-escaping="yes" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="bodyText" disable-output-escaping="yes" /> </xsl:otherwise> </xsl:choose> <a style="width:100%;display:block;" href="{umbraco.library:NiceUrl(@id)}">Learn More »</a> </div> </xsl:template>
But when I am on category where Industries are the subs, nothing shows up. How can I use this XSLT on ALL pages which are "Category," regardless of Product or whatever is underneath it?
The above error I fixed by placing a null check on the articlePhoto field. Thanks.
Bigger issue now-- the "first child slide" functionality is only working on the First child item. The link below will help you understand the structure. I think instead of picking the first Slide child of Each Product, we're picking the first Product only and showing Its first slide.
Here, the Desktop page represents the Category, and each item in the list below (Environment Manager, Application Manager, Performance Manager) represent the Products, and these products have mutiple children which are of document type Slide (which has the property slideImage).
Make sense? Can you help me adjust the code so that we get the first Slide child of EACH Product?
Thanks again, Chriztian -- and sorry to be such a pain -- it's just that this XSLT structure/style is new to me with the multiple template matches. I'll get the hang of it with your continued belief ;)
If you need to put a null-check on articlePhoto there must be something else going on - 'cause that's what articlePhoto[normalize-space()] does; it makes sure to only apply the template if there's a value (other than whitespace) in the property.
- Have you covered all possible child doctypes of Category (e.g.: match="Product | Industry | OtherTypeHere") ?
If you have others and use the *[@isDoc] selector when applying, you'll need to have 'em covered (or maybe ignore them if they're not similar to Product).
Regarding the 1st Slide problem - isn't that exactly what it's doing now? (Taking the 1st Slide child that has a slideImage and showing that image?)
What's the intended output in HTML for e.g. the "Environment Manager"?
Intended output of Use Cases, which is a Category document type, whose children are of type UseCase, which is covered under the <xsl:template match="Product | Industry | CWS_Textpage | UseCase">,for now, is:
<div style="width:100%;height:100%;clear:both;padding:20px 0px 20px 0px;"> <img src="/media/4021/images.jpeg" style="float:left;width:150px;max-height:100px;margin:0px 10px 7px 0px;"/> <h1 style="font-size:2em;padding-bottom:10px;display:inline;"> <a href="/solutions/use-cases/windows-7.aspx">Accelerate Windows 7 Migrations</a> </h1> <p>AppSense enables businesses to realize the benefits of Windows 7 more quickly and at less cost. In managing the most complex and diverse component of the desktop, the user, 'User Virtualization' ensures a proven simple and seamless migration to any new desktop operating system.</p> <a style="width:100%;display:block;" href="/solutions/use-cases/windows-7.aspx">Learn More »</a> </div>
<div style="width:100%;height:100%;clear:both;padding:20px 0px 20px 0px;"> <h1 style="font-size:2em;padding-bottom:10px;display:inline;"> <a href="/solutions/use-cases/windows-7.aspx">Accelerate Windows 7 Migrations</a> </h1> <p>AppSense enables businesses to realize the benefits of Windows 7 more quickly and at less cost. In managing the most complex and diverse component of the desktop, the user, 'User Virtualization' ensures a proven simple and seamless migration to any new desktop operating system.</p> <a style="width:100%;display:block;" href="/solutions/use-cases/windows-7.aspx">Learn More »</a> </div>
In other words everything but the image renders. There is no error, I was mistaken on that part.
Nested Loop > Structure Problem
Hi,
I am looping through the children of the current node, and when I find a node which itself has children, I need to loop through those and show an image which is a property of that child page. Page structure is as follows:
XSLT is as follows:
The field in question is slideImage. The children of the current page might have just an articlePhoto, and when they do, this displays fine; however, some child pages might have a slideShow, which involves the currentPage having child nodes which themselves have a media picker property called a slideImage.
The result I am getting here is all 3 slideImages for the first page in the nested loop, and none for the rest (??). What I want here is to display the First slideImage of each of the children in the nested loop. Haven't got to the first-only issue just because my loop structure seems to be wrong in the first place. What am I missing?
Thanks,
Garrett
Hi Garrett,
Here's how I'd use the benefit of "match templates" to achieve what (I think) you're after - feel free to ask about how it works:
/Chriztian
Thanks Chiztian -- this code is great and will save a lot of time elsewhere!! One thing, though -- under Category, there are Document Types other than Product (I'm trying to use the same template on multiple pages) -- so I copied theProduct one:
But when I am on category where Industries are the subs, nothing shows up. How can I use this XSLT on ALL pages which are "Category," regardless of Product or whatever is underneath it?
Thanks again,
Garrett
Hi Garrett,
You probably just need to change the Category template to not target Product pages specifically, so from this:
to this:
And if your Product and Industry templates are exact copies - just tell the template to match both types, e.g.:
/Chriztian
Thanks again for staying with me here -- I've made those exact changes (they make good sense):
But I am getting a parse error on the front end. It's the apply-templates line. As soon as I remove the Product there I get the error:
For some reason any other nodeset I select in that line gives me the error.
???
The above error I fixed by placing a null check on the articlePhoto field. Thanks.
Bigger issue now-- the "first child slide" functionality is only working on the First child item. The link below will help you understand the structure. I think instead of picking the first Slide child of Each Product, we're picking the first Product only and showing Its first slide.
Here, the Desktop page represents the Category, and each item in the list below (Environment Manager, Application Manager, Performance Manager) represent the Products, and these products have mutiple children which are of document type Slide (which has the property slideImage).
Make sense? Can you help me adjust the code so that we get the first Slide child of EACH Product?
Thanks again, Chriztian -- and sorry to be such a pain -- it's just that this XSLT structure/style is new to me with the multiple template matches. I'll get the hang of it with your continued belief ;)
Thanks,
Garrett
Hi Garrett - no worries; we'll get there :-)
If you need to put a null-check on articlePhoto there must be something else going on - 'cause that's what articlePhoto[normalize-space()] does; it makes sure to only apply the template if there's a value (other than whitespace) in the property.
- Have you covered all possible child doctypes of Category (e.g.: match="Product | Industry | OtherTypeHere") ?
If you have others and use the *[@isDoc] selector when applying, you'll need to have 'em covered (or maybe ignore them if they're not similar to Product).
Regarding the 1st Slide problem - isn't that exactly what it's doing now? (Taking the 1st Slide child that has a slideImage and showing that image?)
What's the intended output in HTML for e.g. the "Environment Manager"?
/Chriztian
Intended output of Use Cases, which is a Category document type, whose children are of type UseCase, which is covered under the <xsl:template match="Product | Industry | CWS_Textpage | UseCase">,for now, is:
This is the code that yields this currently:
Using the apply-templates code:
I get this:
In other words everything but the image renders. There is no error, I was mistaken on that part.
//Garrett
Hi Garrett,
That makes sense - your apply-templates selection says: "Apply templates to any articlePhoto element that has a non-empty articlePhoto element in it"
It needs to be empty to perform the check on itself:
Aternatively, you can use the dot to signal the context node (but that's the default if omitted):
/Chriztian
is working on a reply...