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

Re: Need help on that tricky selection

Subject: Re: Need help on that tricky selection
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 25 May 2004 20:48:03 +0100
xsl ordering selection
Hi Christoph,

> what i want to do is: select all the <ort> elements, complete
> with all their childs, where the <hst> is equal to the <ort_nr>
> and throw the rest away.
>
> one problem is, that i need exactly the order which is given
> within the <hst_list> (the index attribute)
> the other problem may be the performance, because it's possible
> that this xml contains  about 3-5 thousend of <ort> elements

Use a key. This will make the code easy and it will make it as
efficient as it's possible to be. Index the <ort> elements by the
value of their <ort_nr> child:

<xsl:key name="orte" match="ort" use="ort_nr" />

Then you can get the <ort> element with the <ort_nr> 1031501 using:

  key('orte', '1031501')

and if you're currently on a particular <hst> element, you can get the
one corresponding to this <hst> element with:

  key('orte', .)

So to process the <ort> elements in the order specified by the
<hst_list>, you'd do something like:

<xsl:template match="lines">
  <orte>
    <xsl:for-each select="hst_list/hst">
      <xsl:copy-of select="key('orte', .)" />
    </xsl:for-each>
  </orte>
</xsl:template>

The only <ort> elements that will be copied are those selected through
the key, so only those corresponding to an <hst> element. Of course
you could use an <xsl:apply-templates> instead of an <xsl:copy-of> if
you want to process them rather than just get a copy of them.

Oh, and if the <hst> elements might appear in a different order from
that specified by their index attributes, then sort them with:

  <xsl:for-each select="hst_list/hst">
    <xsl:sort select="@index" data-type="number" />
    <xsl:copy-of select="key('orte', .)" />
  </xsl:for-each>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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.