[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: Sun, 28 Nov 2004 23:33:17 -0500 (EST) |
Hi Michael: Thans for help. In actually I found It is good for me to use the xpath to find the logical chilld node to format them. But I have last probelm: How can I get the current node position on the special list? Example: <Subject_List> <Subject_ID> <Subject_Title> <Subject_Parent_ID> </Subject_List> There have three type of node Type A; (Logical parent node) Subject_Parent_ID =1 Type B: (Logical child node and its logical parent node exist) Type C: (Logical child node and its logical parent node do not exist) Subject_Parent_ID not eauql 1 but the logical parent node exist my question: If the current node is belong to type A or type B. How I know It is position for typeA and typeB list. 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 Thanks Helena ______________________________________________________________________ Post your free ad now! http://personals.yahoo.ca
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Problem for : increment a, Michael Kay | Thread | RE: [xsl] Problem for : increment a, Michael Kay |
[xsl] [Problem] transformed code do, Wong Chin Shin | Date | [xsl] newbie xsl questions - groupi, dmitrik |
Month |