[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: GROUPING AND KEYS
It's worth being clear that we're talking here about the Muenchian method of grouping in XSLT 1.0. Grouping in XSLT 2.0 is much much simpler. > 1 - Is there a way to visualise in XSLT what this key looks like? > > <xsl:key name="partNo" match="partNo" use="@num" /> You can think of it like this: "Each document that contains partNo elements has an index, allowing a partNo element to be found quickly if the value of its @num attribute is known". For example, key('partNo', 'P123') returns all the partNo elements whose @num value is P123. > > > In this statement <xsl:for-each > select="foo/shift/partNo[count(. | key('partNo', @num)[1]) = 1]"> In XSLT 1.0, there is no simple way of asking "$A is $B", that is, testing whether two expressions refer to the same node. There are two common workarounds to this: generate-id($A) = generate-id($B) which relies on the fact that if two nodes have the same generated ID then they are the same node, and count($A|$B) = 1 which relies on the fact that the union of two singleton sets is a singleton only if both sets have the same member. In your example, this is the expression you are seeing. Specifically, it's selecting every partNo that is the first partNo with a given @num value. That is "." (the partNo being tested) is the same node as key('partNo', @num)[1], which is the first partNo with that @num value. > > we are selecting all partNo nodes where count(. | key( > 'partNo', @num)[1]) = 1] > > 2 - What does . mean in this expression? the partNo node? Yes, in a predicate "." refers to the node being tested. > > 3 - What does | mean? It's a union operator, it forms the union of two sets. Hope this helps. Michael Kay http://www.saxonica.com/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|