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

Re: Sort>Filter/Modify whatever...

Subject: Re: Sort>Filter/Modify whatever...
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 14 Dec 2001 13:11:34 +0000
xsl filter sort
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.