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

Re: Node list operations

Subject: Re: Node list operations
From: James Clark <jjc@xxxxxxxxxx>
Date: Sun, 09 May 1999 15:23:09 +0700
x expr select
You can do it (albeit inefficiently) like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">

<xsl:template match="v">
  <xsl:text>X Y Z
</xsl:text>
  <xsl:for-each select="w">
    <xsl:sort select="x"/>
    <xsl:sort select="y"/>
    <xsl:sort select="z"/>
    <xsl:choose>
      <xsl:when test="position()=1">
	<xsl:value-of select="x"/>
      </xsl:when>
      <xsl:otherwise>
	<xsl:variable name="pos" expr="position()"/>
	<xsl:variable name="x" expr="x"/>
	<xsl:for-each select="../w">
	  <xsl:sort select="x"/>
	  <xsl:sort select="y"/>
	  <xsl:sort select="z"/>
	  <xsl:if test="position() = $pos - 1">
	     <xsl:choose>
	       <xsl:when test="not(x=$x)">
		 <xsl:value-of select="$x"/>
	       </xsl:when>
	       <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
	     </xsl:choose>
	  </xsl:if>
	</xsl:for-each>
      </xsl:otherwise>
    </xsl:choose> 
    <xsl:text> </xsl:text>
    <xsl:value-of select="y"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="z"/>
    <xsl:text>&#xA;</xsl:text>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

"G. Ken Holman" wrote:
> 
> Hi all,
> 
> XSLT 19990421 is considered "feature complete", yet I've come across what I
> think may represent the need for a frequently-used facility I cannot find
> in the working draft.
> 
> I'm hoping someone on the list can show me if the following problem can,
> indeed, be solved with Working Draft 19990421, because I've tried a lot of
> things and keep getting caught up in the prewired document order of the axes.
> 
> First, here is a problem that I think will be a frequent need that I was
> able to solve in a straightforward fashion, that of suppressing redundant
> entries in a table:
> 
> From:
> 
> <?xml version="1.0"?>
> <v>
> <w><x>1</x><y>1</y><z>a</z></w>
> <w><x>1</x><y>2</y><z>b</z></w>
> <w><x>1</x><y>3</y><z>c</z></w>
> <w><x>2</x><y>1</y><z>d</z></w>
> <w><x>2</x><y>2</y><z>e</z></w>
> <w><x>3</x><y>1</y><z>f</z></w>
> </v>
> 
> Produce:
> 
>  X   Y   Z
>  1   1   a
>      2   b
>      3   c
>  2   1   d
>      2   e
>  3   1   f
> 
> ..... suppressing redundant values for X.

> Now, consider the problem where I want the same output from an unsorted
> collection:
> 
> <?xml version="1.0"?>
> <v>
> <w><x>1</x><y>2</y><z>b</z></w>
> <w><x>3</x><y>1</y><z>f</z></w>
> <w><x>1</x><y>3</y><z>c</z></w>
> <w><x>2</x><y>2</y><z>e</z></w>
> <w><x>2</x><y>1</y><z>d</z></w>
> <w><x>1</x><y>1</y><z>a</z></w>
> </v>

> So, my question is, can this problem be solved with the proposed working
> draft in a single pass, and if not, is it important enough a problem that
> it should be solved with version 1.0?



 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.