Subject: Re: [xsl] Sort>Filter/Modify whatever... From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 14 Dec 2001 13:11:34 +0000 |
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 -> |
---|---|---|
[xsl] Sort>Filter/Modify whatever.., Manos Batsis | Thread | [xsl] sorting related issue, Sanjay Pandey/Towers |
[xsl] Sort>Filter/Modify whatever.., Manos Batsis | Date | Re: [xsl] XSLT and dreamweaver, Robert Koberg |
Month |