[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Problem for : increment a variable in a for-each?
Subject: RE: [xsl] Problem for : increment a variable in a for-each? From: que Li <queincanada@xxxxxxxx> Date: Fri, 26 Nov 2004 19:17:12 -0500 (EST) |
Hi Andrew: Thanks for help. I update xsl file using the template now I have figure out most of them except that one problems.How I can find the current node position inside the correct group? my XSL file: <xsl:template match="SubjectLists"> <xsl:apply-templates /> </xsl:template> <xsl:template match="Subject_List" > <xsl:choose> <xsl:when test="Subject_Parent_ID=1"> <xsl:choose> <xsl:when test="not(preceding-sibling::Subject_List)"> <b><xsl:value-of select="Subject_Title"/></b> </xsl:when> <xsl:when test="not(following-sibling::Subject_List)"> <b> ;<xsl:value-of select="Subject_Title"/></b> </xsl:when> <xsl:otherwise> <b> and <xsl:value-of select="Subject_Title"/></b> </xsl:otherwise> </xsl:choose> <xsl:call-template name="findChildNode"> <xsl:with-param name="ParentID" select="Subject_ID"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="findParentNode"> <xsl:with-param name="ID" select="Subject_Parent_ID"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="findChildNode"> <xsl:param name="ParentID"/> <xsl:for-each select="../Subject_List[Subject_Parent_ID=$ParentID]"> <xsl:choose> <xsl:when test="position()=1 and last() >2 "> <b> ( <xsl:value-of select="Subject_Title"/></b> </xsl:when> <!--only one--> <xsl:when test="position()=1 and last()=1"> <b> ( <xsl:value-of select="Subject_Title"/> )</b> </xsl:when> <!--only two--> <xsl:when test="position()=1 and last()=2 "> <b> ( <xsl:value-of select="Subject_Title"/> </b> </xsl:when> <xsl:when test="position()!=1 and position()=last()"> <b> and <xsl:value-of select="Subject_Title"/> )</b> </xsl:when> <xsl:otherwise> <b> ; <xsl:value-of select="Subject_Title"/></b> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template> <xsl:template name="findParentNode" > <xsl:param name="ID"/> <xsl:if test="count(../Subject_List[Subject_ID=$ID]) = 0"> <xsl:choose> <xsl:when test="not(preceding-sibling::Subject_List)"> <b><xsl:value-of select="Subject_Title"/></b> </xsl:when> <xsl:when test="not(following-sibling::Subject_List)"> <b> ;<xsl:value-of select="Subject_Title"/></b> </xsl:when> <xsl:otherwise> <b> and <xsl:value-of select="Subject_Title"/></b> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:template> XML file: <root> <SubjectLists> <Subject_List> <Subject_ID>31</Subject_ID> <Subject_Title>Biology</Subject_Title> <Subject_Parent_ID>30</Subject_Parent_ID> </Subject_List> <Subject_List> <Subject_ID>32</Subject_ID> <Subject_Title>Chemistry</Subject_Title> <Subject_Parent_ID>30</Subject_Parent_ID> </Subject_List> <Subject_List> <Subject_ID>24</Subject_ID> <Subject_Title>Legal Studies</Subject_Title> <Subject_Parent_ID>1</Subject_Parent_ID> </Subject_List> <Subject_List> <Subject_ID>17</Subject_ID> <Subject_Title>Music</Subject_Title> <Subject_Parent_ID>14</Subject_Parent_ID> </Subject_List> <Subject_List> <Subject_ID>30</Subject_ID> <Subject_Title>Science</Subject_Title> <Subject_Parent_ID>1</Subject_Parent_ID> </Subject_List> <Subject_List> <Subject_ID>18</Subject_ID> <Subject_Title>Visual Arts</Subject_Title> <Subject_Parent_ID>14</Subject_Parent_ID> </Subject_List> </SubjectLists> </root> Now the result is: and Legal Studies and Music and Science ( Biology and Chemistry ) ;Visual Arts the correct result should be: Legal Studies ; Music ; Science ( Biology and Chemistry ) and Visual Arts the reason thst wrong resut is that the preceding-sibling::Subject_List following-sibling::Subject_List should be one group ( That gourp include all node whihc subject_parent_ID is 1 or subject_parent_ID is not one but its parent didn;t exsit(example node:subject_ID is 17 and subject_ID is 18) Thanks Helena ______________________________________________________________________ Post your free ad now! http://personals.yahoo.ca
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Problem for : increment a, que Li | Thread | [xsl] Counting with two conditions, Sven Waibel |
Re: [xsl] IGNORE CASE IN XSLT, Dimtre Novatchev | Date | [xsl] transform a string, Jan Limpens |
Month |