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

Thanks, it works (RE: Sort>Filter/Modify whatever...)

Subject: Thanks, it works (RE: Sort>Filter/Modify whatever...)
From: "Manos Batsis" <m.batsis@xxxxxxxx>
Date: Mon, 17 Dec 2001 10:03:28 +0200
xsl modify element name
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:  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

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.