[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XPath question
This is an example of the classic grouping problem.
Here's an XSLT 1.0 solution: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:template match="data"> <data> <series> <xsl:for-each select="series/event[not(@time=preceding::event/@time)]"> <record time="{@time}"> <xsl:for-each select="//data/series/event[@time=current()/@time]"> <sample ID="{../@ID}"> <xsl:value-of select="."/> </sample> </xsl:for-each> </record> </xsl:for-each> </series> </data> </xsl:template> <xsl:template match="@*|*"> <xsl:copy> <xsl:apply-templates select="@*|*"/> </xsl:copy> </xsl:template> </xsl:stylesheet> Here's an XSLT 2.0 solution (tested on Saxon 7.1): <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:template match="data"> <data> <series> <xsl:for-each-group select="series/event" group-by="@time"> <record time="{@time}"> <xsl:for-each select="current-group()"> <sample ID="{../@ID}"> <xsl:value-of select="."/> </sample> </xsl:for-each> </record> </xsl:for-each-group> </series> </data> </xsl:template> <xsl:template match="@*|*"> <xsl:copy> <xsl:apply-templates select="@*|*"/> </xsl:copy> </xsl:template> </xsl:stylesheet> For an explanation of this new XSLT 2.0 feature (as well as a few others), see the second page of my article[1] on XML.com. Hope this helps, Evan [1] http://www.xml.com/pub/a/2002/04/10/xslt2.html?page=2 On Thursday, May 2, 2002, at 07:45 PM, Joseph Brightly wrote: I'm trying to perform an xml->xml transform and I can't seem to be able to make it work. The following is the xml, with extraneous stuff taken out. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|