[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Identity Transform Grouping Question

Subject: Re: Identity Transform Grouping Question
From: <ethan.kalfus@xxxxxxx>
Date: Wed, 27 Oct 2004 17:21:55 -0400
xsl apply templates select ancestor
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.