[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: in for-each: absolut position

Subject: Re: in for-each: absolut position
From: "Jochen Herrmann" <jochen.herrmann@xxxxxxxx>
Date: Fri, 21 Sep 2001 11:47:08 +0200
absolut position
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.