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

Re: create a new node-set and then reference a key pr

Subject: Re: create a new node-set and then reference a key problem
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 20 Jul 2004 12:29:27 +0100
rooms.xml
I'm confused a bit by the problem statement, I _think_ you are only
trying to select one node, but your stylesheet was generating a table?

  I want to display the roomType whose first occurence
  has a higher "count" value than the other first
  occurences of roomType and whose subsequent "count"
  values are all greater than zero i.e. type 2D in the
  above XML source. I only want to display this room
  type once.

If I ignore "and whose subsequent "count"  values are all greater than
zero" bit then this is selecting the node which is the 1st occurrence of
its id value and no other first occurrence has a greater count, that
could be

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:key name="roomID" match="roomType" use="@id"/>

<xsl:variable name="first"
select="/rooms/roomType[generate-id()=generate-id(key('roomID',@id))]"/>

<xsl:template match="/rooms">
<xsl:copy-of select="$first[not($first/@count &gt; @count)]
 "/>
</xsl:template>

</xsl:stylesheet>

which produces:

$ saxon rooms.xml rooms.xsl
<?xml version="1.0" encoding="utf-8"?>
<roomType id="2" count="6" type="2D"/>


but type2 has a count of zero so you don't want that so...
filter those out:

<xsl:variable name="first"
select="/rooms/roomType[not(key('roomID',@id)/@count=0)]
                       [generate-id()=generate-id(key('roomID',@id))]"/>

which produces


$ saxon rooms.xml rooms.xsl
<?xml version="1.0" encoding="utf-8"?>
<roomType id="3" count="4" type="3D"/>

changing the copy-of to apply templates hopefully lets you produce what
you want.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.