![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: comparing nodes in xslt >Thread Next - Re: comparing nodes in xslt Re: comparing nodes in xsltTo: NULL Date: 10/4/2004 9:35:00 AM inquirydog@h... (inquirydog) writes: > Hi- > > Thanks for the reply. I looked into it a bit and found that > in XSLT 2 you can define xpath functions using xslt elements. This > certainly makes a solution like this more reasonable. It does still > leave certain problems like counting repeat nodes in a list.... For > instance, if you wanted to eliminate doubles in a list like this > > <list> > <element name="1" /> > <element name="2" /> > <element name="1" /> > <element name="1" /> > <element name="1" /> > <element name="2" /> > </list> > > converting to > > <list> > > <element name"1" count="4" /> > <element name="2" count="2" /> > > </list> > > you need to group by element type and then count the number of > elements. Except for very constrained cases this seems to me to be > impossible to do in xslt (yes I know about the muenchian method- it > only works in a constrained case). To do this grouping you need to > first be able to check for node equality (which I think you can do in > xslt 2) and then do the grouping based on the equality (which is > better supported in xslt 2 but still can't do what I describe in this > email). > What do you mean by > but still can't do what I describe in this email. ? Your grouping example seems quite simple to do in either XSLT1 or XSLT2, it might loook a bit simpler in 2 using the explict xsl:for-each-group mechanism, but it doesn't take much code in either case. For example in 1.0 it would be: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key name="x" match="element" use="@name"/> <xsl:template match="list"> <list> <xsl:for-each select="element[generate-id()=generate-id(key('x',@name))]"> <element name="{@name}" count="{count(key('x',@name))}"/> </xsl:for-each> </list> </xsl:template> </xsl:stylesheet> David | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
