Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Grouping problem

From: "Michael Kay" <mike@------------>
To:
Date: 8/1/2005 8:57:00 AM
When comparing two node-sets,

   X = Y

means "some $x in X equals some $y in Y"

But when you do

   name(X) = name(Y)

you are comparing two strings, not two node-sets. If X is a node-set, then
name(X) is the name of the first node in X, and name(Y) is the name of the
first node in Y. (In XSLT 2.0, with version="2.0", you would get an error
trying to apply name() to a node-set containing more than one node. The
change has been made to catch this common mistake.)

In 2.0 you can write

select="*[not(name() = preceding-sibling::*/name())]"

but of course it would be more efficient to use xsl:for-each-group.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Mukul Gandhi [mailto:gandhi.mukul@xxxxxxxxx] 
> Sent: 01 August 2005 07:57
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Grouping problem
> 
> I have the following XML file -
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
>    <a>1</a>
>    <b>2</b>
>    <d>3</d>
>    <d>4</d>
>    <b>5</b>
>    <b>6</b>
>    <c>7</c>
>    <c>8</c> 
>    <a>9</a>  
> </root>
> 
> I am trying to do grouping operation with the following XSL -
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 
> 	<xsl:output method="xml" version="1.0" encoding="UTF-8" 
> indent="yes"/>
> 	
> 	<xsl:template match="/root">
> 	   <groups>
>   	     <xsl:for-each select="*[not(name() = 
> name(preceding-sibling::*))]">
>             <group name="{name()}" />
>    	     </xsl:for-each>
> 	   </groups>
> 	</xsl:template>
> 	
> </xsl:stylesheet>
> 
> I am expecting output -
> <groups>
>    <group name="a" />
>    <group name="b" />
>    <group name="c" />
>    <group name="d" />
> </groups>
> 
> But I get output -
> <?xml version="1.0" encoding="UTF-8"?>
> <groups>
> <group name="a"/>
> <group name="b"/>
> <group name="d"/>
> <group name="d"/>
> <group name="b"/>
> <group name="b"/>
> <group name="c"/>
> <group name="c"/>
> </groups>
> 
> Where is the problem?
> 
> This is tested with Xalan-J 2.6.0 and Saxon 8.4
> 
> Regards,
> Mukul


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent