Re: [xsl] Grouping with keys

Subject: Re: [xsl] Grouping with keys
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 07 Feb 2006 10:12:24 -0500
Dear Silvia,

At 08:11 AM 2/7/2006, you wrote:
Hi prakash,

thanks for helping, this is a good idea, but in my "big" xslt, i have a
construction, where i need a solution with a key.

have you/someone an idea, what4s wrong in my key version?
>
> <xsl:key name="heading" match="wordDorcument/body/sect/p"
> use="generate-id((preceding-sibling::p[pPr/pStyle/@val='Heading1'" />
> <xsl:key name="prog" match="pPr/pStyle/@val='Programlisting'"
> use="generate-id((preceding-sibling::p[pPr/pStyle/@val='Programlisting'"
> />

Without parsing out your XPath, two things come to mind:


* The XPath on the @use attribute isn't
syntactically correct, which one can see readily
due to the lack of closing brackets or
parentheses. This should give you an error.
* You'll probably also want to find the *first*
or immediately preceding p sibling with the selection criterion, as in

generate-id(preceding-sibling::p[pPr/pStyle/@val='Heading1'][1])

-- which you'll need since otherwise you'll get
the generated id of the first such p on the axis
in document order, which isn't what you want for this grouping idiom.

But it may be worth trying Prakash's solution if
it's simpler (hence easier to construct, code and
maintain). People often assume they have to
optimize for performance before they actually do.

I recently saw a fabulous old advertisement for a
machine tooling manufacturer: "If you know you
need new tools and you haven't yet acquired them,
you're already paying for them". This applies to
programming too. But the converse is also true:
if you don't know you need new tools but have
already acquired them, you may be paying extra.

Cheers,
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
======================================================================

Current Thread