Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Chewy key problem

From: Wendell Piez <wapiez@---------------->
To:
Date: 3/1/2005 11:03:00 PM
To add to this,



At 04:22 PM 3/1/2005, David wrote:
Still I'll avoid answering that (because explaining the 2 pass version
is easier:-)first do an identity template

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

Then add a template to work out your sorting key which is, I think



<xsl:template match"b">
<xsl:copy-of select="@*"/>
<xsl:variable name="x">
<xsl:copy-of select=".//desc"/>
</xsl:variable>
<b sort="$x">
<xsl:apply-templates/>
</b>
</xsl:template>

that's all you need the first transform, now you have an intermediate
file that's like your original except every b has a sort attribute.
Now you can just sort/group on that as usual as described in
www.jenitennison.com/xslt/grouping.
You are in a better situation now as your grouping key is just a singke
Xpath @sort.

If you are doing this from java you should be able to avoid the costs of
writing out the intermediate document as a file and parsing it back
again and just pass it as an in memory object from the first transform
to the next. The details of that depend on the API you are using (and
anyway there are others who can tell you a lot more about java.

I'll fill in a bit by adding that two passes can be accomplished in a 
single run of a stylesheet, if you use either XSLT version 2.0, or a very 
popular extension function in XSLT 1.0, usually called node-set().



The node-set() extension is popular enough almost to be official, and for 
an extension, it's very portable: see http://www.exslt.org. The idea here 
is that you would bind the results of the first pass to a variable, use the 
extension function to convert it from a result tree (which, in XSLT 1.0, 
you cannot process further as such, merely copy it or process it as a 
string), and then process the node set you get back as input to your second 
pass. Putting two transforms together like this into a single stylesheet, 
it's probably wise to use modes to disciminate the passes and keep yourself 
from going nuts.



I hope that helps,
Wendell


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent