|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Muenchian Grouping with in a Muenchian Group ???
I've not idea if this is possible. I have a big flat xml file which I cannot change. So I'm hoping XSLT will help.
I found a url jenitennison dot com which has got me part of the way; but now I'm faffing. Here is the out put I'm trying to get Its grouped by Location, then Course and then I'd like every instance of date for its respective grouping. Location A Course A - Date1 - Date2 - Date3 Course B - Date4 - Date5 - Date6 Location B Course A - Date7 - Date8 - Date9 Course B - Date10 - Date11 - Date12 The xsl and xml I've gone back to is just like the example given on jenitennison dot com I spent all day yesterday trying to understand; but with no luck. Any help or link to help is more than welcome I get this which is almost there but not great. Location A Course A - Date1 Course A - Date2 Course B - Date4 Course B - Date5 Location B Course A - Date7 Course A - Date8 Course B - Date10 Course B - Date11 <xsl:key name="course-by-location" match="contact" use="location" /> <xsl:template match="records"> <xsl:for-each select="contact[count(. | key('course-by-location', location)[1]) = 1]"> <xsl:sort select="location" /> <b><xsl:value-of select="location" /></b><br /> <xsl:for-each select="key('course-by-location', location)"> <xsl:sort select="course" /> <xsl:value-of select="course" /> - <xsl:value-of select="date" /><br /> </xsl:for-each><br /> </xsl:for-each> </xsl:template> <records> <contact id="0001"> <date>Date1</date> <course>Course A</course> <location>Location A</location> </contact> <contact id="0002"> <date>Date2</date> <course>Course A</course> <location>Location A</location> </contact> <contact id="0003"> <date>Date3</date> <course>Course D</course> <location>Location A</location> </contact> ... </records> |
|
#2
|
|||
|
|||
|
second level grouping:
Code:
<xsl:key name="date-by-course-location" match="contact" use="concat(location, '-', course)"/>
<xsl:for-each select="key('course-by-location', location)[count(.|key('date-by-course-location', concat(location,'-', course))[1]) = 1]">
<xsl:sort select="course"/>
<xsl:value-of select="course"/>
<xsl:for-each select="key('date-by-course-location', concat(location,'-', course))">
<xsl:text>- </xsl:text>
<xsl:value-of select="date"/>
<br/>
</xsl:for-each>
</xsl:for-each>
|
|
#3
|
|||
|
|||
|
:) its works - it works
Thank you. I wouldn't have got the concat.
For those who are just starting out and learn best from example I have posted the full thing for you to use and change Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="date-by-course-location" match="contact" use="concat(location, '-', course)"/>
<xsl:key name="course-by-location" match="contact" use="location" />
<xsl:template match="records">
<xsl:for-each select="contact[count(. | key('course-by-location', location)[1]) = 1]">
<xsl:sort select="location" />
<b><xsl:value-of select="location" /></b><br />
<xsl:for-each select="key('course-by-location', location)[count(.|key('date-by-course-location', concat(location,'-', course))[1]) = 1]">
<xsl:sort select="course"/>
<xsl:value-of select="course"/>
<xsl:text> - </xsl:text>
<xsl:for-each select="key('date-by-course-location', concat(location,'-', course))">
<xsl:value-of select="date"/>
<xsl:text> </xsl:text>
</xsl:for-each>
<br />
</xsl:for-each>
<br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<tags> xslt
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Muenchian Grouping with in a Muenchian Group ??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|