Subject: Re: [xsl] Identity Transform Grouping Question From: <ethan.kalfus@xxxxxxx> Date: Wed, 27 Oct 2004 17:21:55 -0400 |
Hi Anton, <<in both cases, you'll want to remove "=current()". That should give the correct grouping, and bring back the <address> and <phone> nodes as well>> I had played with that after my last post and it worked...thank you for confirming my suspicions. However, I saw that I still needed a further grouping for <division>, since each country can appear in more than one division (whew!). I modified your version, and it seems to work. For anyone crazy enough to have followed this thread, I'll post the pertinent fragments here for their benefit. If you see anything questionable, please don't hesitate to mention it: <xsl:key name="cities" match="city" use="concat(ancestor::division/@id,'-',ancestor::country/@name,'-',.)"/> <xsl:key name="offices" match="office" use="concat(ancestor::division/@id,'-',ancestor::country/@name,'-',cities/cit y,'-',names/name[@lang='en'])"/> . . . <!-- reorganize 'country' elements --> <xsl:template match="country"> <country> <xsl:copy-of select="@*"/> <cities> <!-- group 'city' elements --> <xsl:apply-templates select="offices/office/cities/city[count(.|key('cities',concat(ancestor::divi sion/@id,'-',ancestor::country/@name,'-',.))[1])=1]"> <xsl:sort select="."/> </xsl:apply-templates> </cities> </country> </xsl:template> <!-- new 'city' elements --> <xsl:template match="city"> <city> <name> <xsl:value-of select="."/> </name> <offices> <!-- group 'office' elements *located in this city* by their english name --> <xsl:apply-templates select="ancestor::offices/office[cities/city=current() and count(.|key('offices',concat(ancestor::division/@id,'-',ancestor::country/@na me,'-',cities/city,'-',names/name[@lang='en']))[1])=1]"> <xsl:sort select="names/name[@lang='en']"/> </xsl:apply-templates> </offices> </city> </xsl:template> <!-- new office elements --> <xsl:template match="office"> <office> <xsl:apply-templates select="names"/> <!-- add locations for each office with this name --> <xsl:apply-templates select="key('offices',concat(ancestor::division/@id,'-',ancestor::country/@na me,'-',cities/city,'-',names/name[@lang='en']))" mode="location"/> </office> </xsl:template> . . . . Finally, the last issue seems to be performance. I had originally mentioned another solution that someone had assisted me with that employed for-each rather than templates and used the Muenchian method as well. It performed well -- 2 seconds to transform a 3MB file, although it didn't group to the number of levels as above (though I suspect it would not have made a significant difference). However, the templates-based solution above takes about 45 seconds, which is of course a major difference. I'm not sure why (perhaps the number of keys stored in memory due to the various grouping levels, or the use of "ancestor"?), or where improvements could be made, so I may need to revisit the other solution. Thanks again for the support, Anton! Visit our website at http://www.ubs.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Identity Transform Groupi, Anton Triest | Thread | Re: [xsl] Identity Transform Groupi, Anton Triest |
Re: [xsl] Retrieving top section fr, Dimtre Novatchev | Date | Re: [xsl] Identity Transform Groupi, Anton Triest |
Month |