This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Thanks, it works (RE: Sort>Filter/Modify whatever...)
- From: "Manos Batsis" <m dot batsis at bsnet dot gr>
- To: "Jeni Tennison" <jeni at jenitennison dot com>
- Cc: <xsl-list at lists dot mulberrytech dot com>
- Date: Mon, 17 Dec 2001 10:03:28 +0200
- Subject: Thanks, it works (RE: [xsl] Sort>Filter/Modify whatever...)
- Reply-to: xsl-list at lists dot mulberrytech dot com
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@jenitennison.com]
> Sent: Friday, December 14, 2001 3:12 PM
> To: Manos Batsis
> Cc: xsl-list@lists.mulberrytech.com
> 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