I have this xslt wherein I list all the available spa treatments. I wanted to list it according to group. I try using keys but id doesn't display any result. For now this is the sample xslt that I have.
Actually the data is displaying and it is already sorted. But I wanted to display the <h2 class="subhead"><xsl:value-of select="treatmentCategory"/></h2> only once because it's how I want to group my listing.
In my page there is a button for spa treatments. When the user clicks it I will display a lightbox that list all the treatments under serenity spa and group it according to the treatment category that I defined.
The code I posted above just display all the treatments (e.g. Express back massage) sorted according to treatment category. But what I want is to display it on my page like
You should be able to do this using keys to get a unique list of Categories, then use another loop to loop through all services of that category. Here's a quick example:
Though one question, why is it it's not listing all the nodes? it just display 2 treatmentCategory but when I don't use this keys all the treatmentCategory displays accordingly.
Help in grouping the node in xslt
Hi guys,
I have this xslt wherein I list all the available spa treatments. I wanted to list it according to group. I try using keys but id doesn't display any result. For now this is the sample xslt that I have.
<xsl:variable name="nodeID" select="umbraco.library:RequestQueryString('nodeID')"/>
<xsl:template match="/">
<xsl:for-each select="umbraco.library:GetXmlNodeById($nodeID)/* [@isDoc]">
<xsl:sort select="treatmentCategory" order="ascending" />
<h2 class="subhead"><xsl:value-of select="treatmentCategory"/></h2>
<div class="contentSub">
<div class="treatmentMain">
<div class="treatment"><h3 class="treatmentHead"><xsl:value-of select="treatmentName"/></h3></div>
<div class="treatmenttime"><xsl:value-of select="priceRange"/></div>
<div class="clear"> </div>
<xsl:value-of select="treatmentDescription" disable-output-escaping="yes"/>
</div>
</div>
</xsl:for-each>
Hey Sherry,
Is the problem that the data isn't displaying, or just that it's not sorting correctly?
Rich
Actually the data is displaying and it is already sorted. But I wanted to display the <h2 class="subhead"><xsl:value-of select="treatmentCategory"/></h2> only once because it's how I want to group my listing.
I want it to display like this
Massages -> This is the treatment category
Back Massage
Foot Massage
Because now it is displaying my data as
Massages
Back Massage
Massages
Foot Masssage
Hi Sherry,
Just add something like this
<xsl:if test="position()=1"> <h2 class="subhead"><xsl:value-of select="treatmentCategory"/></h2> </xsl:if>
Rich
What if I have another grouping? Like this
Massages
Back Massage
Massages
Foot Masssage
Treatment
Facial Treatment
Treatment
Hair Spa
And I wanted it to display like
Massages
Back Massage
Foot Massage
Treatment
Facial Treatment
Hair Spa
Hi Sherry,
It would help if you posted an image of your content structure.
Rich
This is the layout of my node.
In my page there is a button for spa treatments. When the user clicks it I will display a lightbox that list all the treatments under serenity spa and group it according to the treatment category that I defined.
The code I posted above just display all the treatments (e.g. Express back massage) sorted according to treatment category. But what I want is to display it on my page like
Massages
Express Back Massage
Express Legs Massage
Hey Sherry,
I'm not sure if it's too late for you, however it might have been better to have a structure like this:
- Spa
- Massage
Back Massage
Head Massage
- Treatment
- Mens Facial
- Womes Facial
I'm not sure how to solve it using the structure you have right now, where is the list of Treatment Categories coming from?
Rich
Hi,
You should be able to do this using keys to get a unique list of Categories, then use another loop to loop through all services of that category. Here's a quick example:
If not using currentPage you'll need to adjust the xpath accordingly.
Note there are probably cleaner ways to write this with xsl:templates but I haven't experimented yet :)
Thanks for that. :D
Though one question, why is it it's not listing all the nodes? it just display 2 treatmentCategory but when I don't use this keys all the treatmentCategory displays accordingly.
Here's my code.
Hmm...are the other treatmentCategory's actually in use, like specified on some of the services nodes? If not they won't show up
is working on a reply...