Subject: RE: [xsl] Recursion Problem From: vsubramanian@xxxxxxxxxx Date: Thu, 27 May 2004 11:05:24 -0400 |
Just a note for people who use the following code - ---------------------------------------------------------------------------- - <xsl:template match="service_list"> <serv_list> <xsl:apply-templates select="service[1]"/> </serv_list> </xsl:template> <xsl:template match="service"> <xsl:variable name="group" select=". | following-sibling::service[position() < 6][name = current()/name]"/> <final_serv_list> <xsl:copy-of select="name"/> <xsl:copy-of select="cr_case_id_fk"/> <xsl:for-each select="$group/claim_amount"> <xsl:element name="{concat(name(), '_', position())}"> <xsl:value-of select="."/> </xsl:element> </xsl:for-each> <xsl:if test="count($group) < 6"> <xsl:for-each select="(document('')//*)[position() <= (6 - count($group))]"> <serv_list/> </xsl:for-each> </xsl:if> </final_serv_list> <xsl:apply-templates select="following-sibling::service[count($group)]"/> </xsl:template> ---------------------------------------------------------------------------- - Please substitute <xsl:variable name="group" select=". | following-sibling::service[position() < 6][name = current()/name]"/> with id or whatever your unique key is ( as below). <xsl:variable name="group" select=". | following-sibling::service[position() < 6][id = current()/id]"/> This would solve the problem if you have 2 people with same names but different ids. Thanks, Vidya -----Original Message----- From: Jarno.Elovirta@xxxxxxxxx [mailto:Jarno.Elovirta@xxxxxxxxx] Sent: Wednesday, May 26, 2004 12:35 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] Recursion Problem Hi, > I am having a problem with recursion. > A student can have multiple claims & I am trying to group 6 > claims in every > node. I tried to do recursion but, i lose one node always with every > recursion <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:key name="name" match="service" use="name"/> <xsl:template match="service_list"> <serv_list> <xsl:for-each select="service[generate-id(.) = generate-id(key('name', name))]"> <xsl:call-template name="group"> <xsl:with-param name="node-set" select="key('name', name)"/> </xsl:call-template> </xsl:for-each> </serv_list> </xsl:template> <xsl:template name="group"> <xsl:param name="node-set"/> <final_serv_list> <xsl:copy-of select="$node-set[1]/name"/> <xsl:copy-of select="$node-set[1]/cr_case_id_fk"/> <xsl:for-each select="$node-set[position() <= 6]/claim_amount"> <xsl:element name="{concat(name(), '_', position())}"> <xsl:value-of select="."/> </xsl:element> </xsl:for-each> <xsl:if test="count($node-set) < 6"> <xsl:for-each select="(document('')//*)[position() <= (6 - count($node-set))]"> <serv_list/> </xsl:for-each> </xsl:if> </final_serv_list> <xsl:if test="count($node-set) > 6"> <xsl:call-template name="group"> <xsl:with-param name="node-set" select="$node-set[position() >= 7]"/> </xsl:call-template> </xsl:if> </xsl:template> or if the services are always ordered as they are in your example <xsl:template match="service_list"> <serv_list> <xsl:apply-templates select="service[1]"/> </serv_list> </xsl:template> <xsl:template match="service"> <xsl:variable name="group" select=". | following-sibling::service[position() < 6][name = current()/name]"/> <final_serv_list> <xsl:copy-of select="name"/> <xsl:copy-of select="cr_case_id_fk"/> <xsl:for-each select="$group/claim_amount"> <xsl:element name="{concat(name(), '_', position())}"> <xsl:value-of select="."/> </xsl:element> </xsl:for-each> <xsl:if test="count($group) < 6"> <xsl:for-each select="(document('')//*)[position() <= (6 - count($group))]"> <serv_list/> </xsl:for-each> </xsl:if> </final_serv_list> <xsl:apply-templates select="following-sibling::service[count($group)]"/> </xsl:template> Hope this helps, Jarno - Simon Eve: December 2002 Mix
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Recursion Problem, vsubramanian | Thread | [xsl] Conditional Grouping Problem, Jonathan Kart |
RE: [xsl] MSXML and unwanted entity, Passin, Tom | Date | [xsl] NEED good information on alte, Steve Brown |
Month |