Subject: Thanks, it works (RE: [xsl] Sort>Filter/Modify whatever...) From: "Manos Batsis" <m.batsis@xxxxxxxx> Date: Mon, 17 Dec 2001 10:03:28 +0200 |
Jeni, Thanks! You forced me to understand keys, something I was after for two months but had no time for (or so I thought). Kindest regards, Manos > -----Original Message----- > From: Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx] > Sent: Friday, December 14, 2001 3:12 PM > To: Manos Batsis > Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: [xsl] Sort>Filter/Modify whatever... > > > Hi Manos, > > > As I have thought of it, for each element of name=*, I have to check > > for elements with the same name, then look within their permission > > attr to pic the one I want or build one if multiple same_name > > elements exist with a combination of persmission attrs that should > > become one complex one. > > I'd approach this as a grouping problem, and use the old Muenchian > Method. Index all the USER elements by their name attribute using a > key: > > <xsl:key name="users" match="USER" use="@name" /> > > Then you can just pick on the USER elements that are the first with > that name within the document using: > > <xsl:template match="USERS"> > <USERS> > <xsl:apply-templates > select="USER[generate-id() = generate-id(key('users', > @name)[1])]" /> > </USERS> > </xsl:template> > > Have a template that matches USER elements. You know that this > template will only be applied to the first USER with a particular > @name, so you can safely create a USER element with that name > attribute: > > <xsl:template match="USER"> > <USER name="{@name}"> > ... > </USER> > </xsl:template> > > When creating the permission attribute, you need to work out whether > there are any other USER elements in the document with the same name. > You can find out using the key again, retrieving all the USER elements > that have the name of the current USER: > > <xsl:template match="USER"> > <USER name="{@name}"> > <xsl:attribute name="permission"> > <xsl:variable name="permissions" > select="key('users', @name)/@permission" /> > ... > </xsl:attribute> > </USER> > </xsl:template> > > Now you need to sort out your priorities and work out what new > permission attribute to add. It might look something like: > > <xsl:template match="USER"> > <USER name="{@name}"> > <xsl:attribute name="permission"> > <xsl:variable name="permissions" > select="key('users', @name)/@permission" /> > <xsl:choose> > <!-- if any of the permissions is 'none', then it should be > 'none' --> > <xsl:when test="$permissions = 'none'">none</xsl:when> > <!-- if there's a 'read' permission and a 'write' permission > then it should be 'read-write' --> > <xsl:when test="$permissions = 'read' and > $permissions = 'write'">read-write</xsl:when> > ... > <!-- if we get here, just use the first permission --> > <xsl:otherwise> > <xsl:value-of select="$permissions" /> > </xsl:otherwise> > </xsl:choose> > </xsl:attribute> > </USER> > </xsl:template> > > I hope that helps, > > Jeni > > --- > Jeni Tennison > http://www.jenitennison.com/ > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] document() and fragment, David Carlisle | Thread | [xsl] xsl:apply-templates - Specify, Ganesh Suriyanarayan |
Re: [xsl] recursive output numberin, Emiliano | Date | [xsl] xsl:apply-templates - Specify, Ganesh Suriyanarayan |
Month |