Subject: Re: Node list operations From: James Clark <jjc@xxxxxxxxxx> Date: Sun, 09 May 1999 15:23:09 +0700 |
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>
</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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Node list operations, G. Ken Holman | Thread | Re: Node list operations, G. Ken Holman |
Re: Simple suggestion for XSLT, James Clark | Date | Re: Simple suggestion for XSLT, David LeBlanc |
Month |