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

Re: Grouping with keys

Subject: Re: Grouping with keys
From: "G. T. Stresen-Reuter" <tedmasterweb@xxxxxxxxx>
Date: Thu, 24 Oct 2013 19:05:29 +0100
Re:  Grouping with keys
On Oct 24, 2013, at 4:34 PM, Rick Quatro <rick@xxxxxxxxxxxxxx> wrote:

> <xsl:key name="orderedlist" match="xhtml:p[@class='listitem1' or
>
@class='listitem2'][preceding-sibling::*[1][self::xhtml:p[@class='listitem1'
> or @class='listitem2']]]"
>        use="generate-id(preceding-sibling::xhtml:p[@class='listitem1' or
>
@class='listitem2'][not(preceding-sibling::*[1][self::xhtml:p[@class='listit
> em1' or @class='listitem2']])])" />

Hi,

Leaving aside for the moment exactly what you're trying to do, try to keep in
mind that you specify the element you want to capture in the MATCH attribute.
The USE attribute, then, is an XPath from the MATCHed element to the node you
want to use as a key (the group identifier).

Also, if possible, please provide a simplified version of the problem. I'm
unable to process what you've sent and looking at it. I'm having trouble
identifying what you are trying to key off of.

That said, here's my best *UNTESTED* attempt at answering your query (and note
that there will be some issues with the START attribute in your OL element).

<xsl:key name="listitems" match="p[starts-with(@class, 'listitem')]"
use="preceding-sibling::p[starts-with(@class, 'listintro') or
starts-with(@class, 'caption')]" />

<xsl:template match="p[not(starts-with(@class, 'listitem'))]">
	<xsl:copy-of select="." />
	<xsl:variable name="currP" select="." />
	<xsl:variable name="Ppos" select="position()" />
	<xsl:if test="count(key('listitems', .)) &gt; 0">
		<xsl:element name="ol">
			<xsl:attribute name="start"><xsl:value-of select="$PPos"
/></xsl:attribute>
			<xsl:for-each select="key('listitems', $currP)">
				<xsl:element name="li">
					<xsl:value-of select="." />
				</xsl:element>
			</xsl:for-each>
		</xsl:element>
	</xsl:if>
</xsl:template>

Also note that you are going to have duplicate numbers in the rendered HTML as
the LI element inside an OL element will prepend the contents with a number
and your contents already contains a number.

Ted Stresen-Reuter

(Feels good to be back in the game, just wish it was a full time gig.)

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.