Subject: Re: [xsl]in for-each: absolut position From: "Jochen Herrmann" <jochen.herrmann@xxxxxxxx> Date: Fri, 21 Sep 2001 11:47:08 +0200 |
Hi Yang, thank you for your solution. I tried too, and that's my solution; it´s nearly the same, but I select only the groups with more than 1 element A good idea is to use "::" in the concat. ...and now I got here a new problem: i need the correct positions of the concerned <row>s, for example 3 rows are equal, so i need three absolut positions like 10, 12, 13 position() within the group gains 1,2,3 and the solution with select="count(//row[@name0=$v_name0 and @name1=$v_name1]/preceding-sibling::*)+1" produces the last postion. have you got any idea? thanks and by Jochen <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/REC-html40"> <xsl:output method="html"/> <xsl:strip-space elements="*"/> <xsl:key name="rowkey" match="row" use="concat(@name0,@name1)"/> <xsl:template match="/gentable"> <xsl:apply-templates select="//row[generate-id(.) = generate-id(key('rowkey',concat(@name0,@name1))[1]) and count(key('rowkey',concat(@name0,@name1)))>1]" /> </xsl:template> <xsl:template match="row"> <xsl:variable name="v_name0" select="@name0"/> <xsl:variable name="v_name1" select="@name1"/> <xsl:variable name="pos1" select="count(//row[@name0=$v_name0 and @name1=$v_name1]/preceding-sibling::*)+1"/> <xsl:variable name="anzahl" select="count(key('rowkey',concat(@name0,@name1)))"/> <xsl:if test="$anzahl > 1"> Eintrag '<xsl:value-of select="@name0" />,<xsl:value-of select="@name1" />' ist <xsl:value-of select="$anzahl" />-fach definiert. Zeile <xsl:value-of select="$pos1"/> </xsl:if> </xsl:template> </xsl:stylesheet> Yang schrieb: > > Hi ,Jochen > > For your problem, Mike specifically points out this is type of group ; > > >This is essentially a grouping problem, where you are only interested in > >groups of size 2 or more. As the grouping key is a compound key (it's not > >the string-value of a node), take a look at Muenchian grouping, > > Base on your posted xml and xsl , the following xslt using Muenchian method > with the compound key of attr name0 and name1 is given here for your > reference. > Hope you will find it useful. > > <?xml version="1.0" encoding="ISO-8859-1" ?> > - <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns="http://www.w3.org/TR/REC-html40"> > <xsl:output method="html" /> > <xsl:key name="checkItem" match="row" use="concat(@name0,'::',@name1)" /> > <xsl:strip-space elements="*" /> > - <xsl:template match="/gentable"> > > - <xsl:for-each > select="body/row[generate-id(.)=generate-id(key('checkItem',concat(@name0,': > :',@name1))[1])]"> > - <xsl:if test="count(key('checkItem',concat(@name0,'::',@name1)))>1"> > <br /> > (name0: > <xsl:value-of select="@name0" /> > name1: > <xsl:value-of select="@name1" /> > ) > <xsl:text>are duplicated.</xsl:text> > <xsl:text>They are located in</xsl:text> > <br /> > <xsl:apply-templates select="key('checkItem',concat(@name0,'::',@name1))" > /> > <br /> > </xsl:if> > </xsl:for-each> > </xsl:template> > - <xsl:template match="row"> > Line > <xsl:number /> > - <xsl:if test="position()!=last()"> > <xsl:text>;</xsl:text> > </xsl:if> > </xsl:template> > </xsl:stylesheet> > > Cheers, > > Sun-fu Yang > sfyang@xxxxxxxxxxxxx > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] ReRe: in for-each apply-templ, Yang | Thread | [xsl] Re:FW: How to realize documen, Yang |
[xsl] Counting Footnotes, Nicholas Waltham | Date | RE: [xsl] Counting Footnotes, Michael Kay |
Month |