This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: in for-each: absolut position
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl]in for-each: absolut position
- From: "Jochen Herrmann" <jochen dot herrmann at danet dot de>
- Date: Fri, 21 Sep 2001 11:47:08 +0200
- References: <001001c141a0$98ea4fb0$1601800a@hqlab.unisvr>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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@unisvr.net.tw
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list