Subject: [xsl] Please help Problem for : increment a variable in a for-each? From: que Li <queincanada@xxxxxxxx> Date: Tue, 30 Nov 2004 13:28:49 -0500 (EST) |
Hi all: I got so many peopel help but I can't get solution for my problem yet. I need fix it asap so please help me ! question is : How I can find relatiove position on the node which satify the condition ? I try to set the variable called index and increment index value when I call template but the index value is always 1 I work on this problems for several days, I wish I can get help for solution. Thanks xml file: <Lists> <List > <List_ID>10</List_ID> <Title>A</Title> <Parent_ID>1</Parent_ID> </List> <List> <List_ID>11</List_ID> <Title>A1</Title> <Parent_ID>10</Parent_ID> </List> <List > <List_ID>12</List_ID> <Title>B</Title> <Parent_ID>20</Parent_ID> </List> <List > <List_ID>13</List_ID> <Title>A2</Title> <Parent_ID>10</Parent_ID> </List> <List > <List_ID>14</List_ID> <Title>C</Title> <Parent_ID>1</Parent_ID> </List> </Lists> xsl: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:template match="Lists" > <xsl:apply-templates> <xsl:with-param name="ValidCount" select="number(count(List)-count(List[Parent_ID=../List/List_ID]))"/> </xsl:apply-templates> </xsl:template> <xsl:template match="List"> <xsl:param name="ValidCount"/> <xsl:variable name="self" select="."/> <xsl:variable name="index" select="0"/> <xsl:choose> <xsl:when test="Parent_ID=1 or not(preceding-sibling::List[List_ID = $self/Parent_ID] or following-sibling::List[List_ID = $self/Parent_ID])"> <xsl:call-template name="formatTitle"> <xsl:with-param name="index" select="$index+1"/> <xsl:with-param name="TotalCount" select="$ValidCount"/> <xsl:with-param name="Title" select="Title"/> </xsl:call-template> <xsl:call-template name="findChildNode"> <xsl:with-param name="ParentID" select="List_ID"/> </xsl:call-template> </xsl:when> </xsl:choose> </xsl:template> <xsl:template name="findChildNode"> ....this part work </xsl:template> <xsl:template name="formatTitle"> <xsl:param name="index" /> <xsl:param name="TotalCount"/> index: <xsl:value-of select="$index"/> <xsl:param name="Title"/> <xsl:choose> <xsl:when test="$TotalCount=1 or $index=1"> <b><xsl:value-of select="$Title"/></b> </xsl:when> <xsl:when test="$index = $TotalCount -1"> <b> and <xsl:value-of select="$Title"/></b> </xsl:when> <xsl:when test="$index = $TotalCount"> <b> <xsl:value-of select="$Title"/></b> </xsl:when> <xsl:otherwise> <b>; <xsl:value-of select="$Title"/></b> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> ______________________________________________________________________ Post your free ad now! http://personals.yahoo.ca
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Problem for : increment a, que Li | Thread | RE: [xsl] Please help Problem for :, Michael Kay |
Re: [xsl] XML Data Islands, XML Men, M. David Peterson | Date | Re: [xsl] how to set the pattern to, que Li |
Month |