Subject: Node list operations From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sat, 08 May 1999 16:28:47 -0400 |
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. This was really straightforward because the document order is in sorted order: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"> <xsl:template match="/"> <!--root rule--> <xsl:text > X Y Z </xsl:text> <xsl:apply-templates mode="next" select="//w"/> </xsl:template> <xsl:template name="show-entry"> <xsl:param-variable name="x-value" expr="' '"/> <xsl:text> </xsl:text><xsl:value-of select="$x-value"/> <xsl:text> </xsl:text><xsl:value-of select="y"/> <xsl:text> </xsl:text><xsl:value-of select="z"/><xsl:text> </xsl:text> </xsl:template> <xsl:template mode="next" match="*"> <xsl:variable name="this" expr="x"/> <xsl:choose> <xsl:when test="not(from-preceding-siblings(w[x=$this]))"> <xsl:call-template name="show-entry"> <xsl:param name="x-value" expr="$this"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="show-entry"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> 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> Given that all the axes are interpreted with candidate nodes in document order, not node-set order, I cannot find a way to solve this problem with the proposed XSLT 1.0. Every time I try to "look back" to previous siblings in the node set, the axes available to me constrain me to document order, not to the node-set order. Same thing when I try to "walk" through a node list, since subsetting the node list using apply-templates again interprets the axes in document order. Going through the axes, each non-attribute one explicitly states it orientation with respect to document order. I think I could solve it if I had a more complete set of node list operations along the lines of: (1) - either: assign context node list to a variable or: allow <xsl:sort> as a child of <xsl:variable> for use when the exprssion is a NodeSetExpr (2) - node-list-first( nodeSetExpr ) (or a node set preceding axis) (3) - node-list-rest( nodeSetExpr ) (or a node set following axis) and then use call-template with variables and "walk through" the sorted node set. .... but I recognize it is *not* in the spirit of the current review of the working draft to be suggesting new features (unless absolutely necessary?), so I'm trying to solve this problem using the current working draft. I recognize this can be done in a two-pass fashion, sorting the information first into a new XML file and then working with the various document-order axes to get the desired result. 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? Thanks for any ideas you may have. .............. Ken -- G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) Website: XSL/XML/DSSSL/SGML services outline, XSL/DSSSL shareware, stylesheet resource library, conference training schedule, commercial stylesheet training materials, on-line XSL CBT. Next instructor-led XSLT Training: WWW8:1999-05-11 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Part B - Generic parse.allXML f, G. Ken Holman | Thread | Re: Node list operations, James Clark |
Re: Part A - Generic parse.allXML f, Matthew MacKenzie | Date | Re: Simple suggestion for XSLT, James Clark |
Month |