Subject: [xsl] Inconsistent solution from a conditional data-set by group methods From: "Yang" <sfyang@xxxxxxxxxxxxx> Date: Fri, 20 Apr 2001 13:58:02 +0800 |
Hi, Everyone, I intend to sort out a list of name based on month which can be singled out from position 10,11 of salesno element in a xml file listed below. However I get myself with some inconsistent solutions. Using Muenchian procedures , I define key function as following phrase, <xsl:key name="Listings" match="line" use="name" /> and then supposedly obtain a set of unique set of name listing from: <xsl:for-each select="//line[substring(salesno,10,2)='03'][generate-id(.)=generate-id(key( 'Listings',name)[1])]"> <xsl:value-of select="name"/> </xsl:for-each> But it does not produce a good solution. So I change key function by adding predicates [substring(salesno,10,2)='03'] , such as <xsl:key name="Listing2" match="line[substring(salesno,10,2)='03']" use="name"/> then use it with for-each element and then get a good solution this time. My understanding that the node-set with Listing2 is a subset of the one from Listing key. So the solution from using Listings key should be at least the same as the one from Listing2. Apparently the solution of this example defies to my thinking. Would Someone help me to clarify the above inconsistent solution issue? I am using ie5 and mxxml3. Much thanks in advance. I have xml, xsl and output listed below. **xml** <?xml version="1.0" ?> <?xml-stylesheet href="key2.xsl" type="text/xsl"?> <docs> <line><name>AAA</name><salesno>B001-1-0101110093</salesno></line> <line><name>BBB</name><salesno>B001-1-0101110094</salesno></line> <line><name>BBB</name><salesno>B001-1-0101110095</salesno></line> <line><name>AAA</name><salesno>B001-1-0101110096</salesno></line> <line><name>CCC</name><salesno>B001-1-0101110097</salesno></line> <line><name>BBB</name><salesno>B001-1-0101150120</salesno></line> <line><name>BBB</name><salesno>B001-1-0101150121</salesno></line> <line><name>AAA</name><salesno>B001-1-0101150122</salesno></line> <line><name>AAA</name><salesno>B001-1-0101150123</salesno></line> <line><name>DDD</name><salesno>A001-1-0101170004</salesno></line> <line><name>BBB</name><salesno>B001-1-0101150124</salesno></line> <line><name>BBB</name><salesno>B001-1-0101150125</salesno></line> <line><name>AAA</name><salesno>B001-1-0101180126</salesno></line> <line><name>AAA</name><salesno>B001-1-0101190127</salesno></line> <line><name>EEE</name><salesno>B001-1-0101300128</salesno></line> <line><name>DDD</name><salesno>A001-1-0102020001</salesno></line> <line><name>FFF</name><salesno>B001-1-0102020001</salesno></line> <line><name>DDD</name><salesno>B001-1-0102090003</salesno></line> <line><name>AAA</name><salesno>B001-1-0102180005</salesno></line> <line><name>DDD</name><salesno>A001-1-0101190005</salesno></line> <line><name>DDD</name><salesno>B001-1-0102090002</salesno></line> <line><name>AAA</name><salesno>B001-1-0102150004</salesno></line> <line><name>AAA</name><salesno>A001-1-0103010001</salesno></line> <line><name>DDD</name><salesno>A001-1-0103020002</salesno></line> <line><name>AAA</name><salesno>B001-1-0103050005</salesno></line> <line><name>AAA</name><salesno>B001-1-0103060006</salesno></line> <line><name>GGG</name><salesno>B001-1-0103070007</salesno></line> <line><name>AAA</name><salesno>B001-1-0103010001</salesno></line> <line><name>BBB</name><salesno>B001-1-0103010002</salesno></line> <line><name>AAA</name><salesno>B001-1-0103010003</salesno></line> <line><name>AAA</name><salesno>B001-1-0103010004</salesno></line> </docs> *** xsl **** <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:param name="heading" select="//line"/> <xsl:param name="month" select="'03'"/> <xsl:variable name="MSource" select="$heading[substring(salesno,10,2)=$month]"/> <xsl:key name="Listings" match="line" use="name" /> <xsl:key name="Listing2" match="line[substring(salesno,10,2)='03']" use="name"/> <xsl:template match="/"> Month:<xsl:value-of select="$month"/> <br/> <b>no predicates to the key function, the solution is wrong. </b> <br/> name: <xsl:for-each select="$MSource[generate-id(.)=generate-id(key('Listings',name)[1])]"> <xsl:sort select="name"/> <xsl:value-of select="name"/> <text>,</text> </xsl:for-each> <br/> <b>2 add predicates to the key function, and it is the correct unique set.</b><br/> name: <xsl:for-each select="$MSource[generate-id(.)=generate-id(key('Listing2',name)[1])]"> <xsl:sort select="name"/> <xsl:value-of select="name"/> <text>,</text> </xsl:for-each> <br/> <b>3 non-unique data-set solutions</b><br/> name: <xsl:for-each select="$MSource"> <xsl:sort select="name"/> <xsl:value-of select="name"/> <text>,</text> </xsl:for-each> <br/> </xsl:template> </xsl:stylesheet> *** output for the month of 3 Month:03 no predicates to the key function, the solution is wrong. name: GGG , 2 add predicates to the key function, and it is the correct unique set. name: AAA ,BBB ,DDD ,GGG , 3 non-unique data-set solutions name: AAA ,AAA ,AAA ,AAA ,AAA ,AAA ,BBB ,DDD ,GGG XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] <xsl:number from=...> dif, Michael Kay | Thread | Re: [xsl] Inconsistent solution fro, Jeni Tennison |
[xsl] <xsl:number from=...> differe, MURAKAMI Shinyu | Date | Re: [xsl] Inconsistent solution fro, Jeni Tennison |
Month |