[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: RE: flat structure to deep structure in a smart wa
Dear Michael, Many thanks for the link. The article is a real eye-opener. So I started: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:key name="A-key" match="line" use="item[@itemcount=1]"/> <xsl:key name="B-key" match="line" use="item[@itemcount=2]"/> <xsl:key name="C-key" match="line" use="item[@itemcount=3]"/> <xsl:template match="root"> <xsl:element name="result"> <xsl:for-each select="line[count(. | key('A-key', item[@itemcount=1])[1]) = 1]"> <xsl:element name="A"> <xsl:attribute name="Value"><xsl:value-of select="item[@itemcount=1]" /></xsl:attribute> <xsl:for-each select="key('A-key', item[@itemcount=1])"> <!-- we need to group the B-elements How do we do that here ? --> <xsl:element name="B"> <xsl:attribute name="Value"><xsl:value-of select="item[@itemcount=2]"/></xsl:attribute> </xsl:element> </xsl:for-each> </xsl:element> </xsl:for-each> </xsl:element> </xsl:template> </xsl:stylesheet> which brings me: <?xml version="1.0" encoding="UTF-8"?> <result> <A Value="A1"> <B Value="B1"/> <B Value="B22"/> </A> <A Value="A3"> <B Value="B3"/> <B Value="B3"/> <B Value="B3"/> </A> </result> Now I got a bit stuck. Under the A3 I need to group the B-elements again. How do I do that ? I presume I need to change/add something to the <xsl:for-each select="key('A-key', item[@itemcount=1])"> line but it is not entirely clear how to do that. P.S. Once this is solved I will post the full stylesheet as I think this a very typical problem from a sorted database table. Many thanks in advance Jozef Michael Kay <mike@xxxxxxxxxxxx> schrieb am 24.09.2004, 19:22:44: > > In the element you see an A1 again, so B22 > > should fall > > under A1 that's under line 1. I.e. if an element has the same value as > > in the previous line, it should become a subelement of the first line. > > > > > > What is the best strategy to accomplish this ? > > > > As mentioned several times in the last couple of days, read > > http://www.jenitennison.com/xslt/grouping > > Michael Kay > http://www.saxonica.com/
|
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
|