[xsl] question on preceding nodes

Subject: [xsl] question on preceding nodes
From: "Liao, John Teguh (John)" <jliao@xxxxxxxxxx>
Date: Mon, 31 Mar 2003 18:07:52 -0500
Hi list

I would like to understand the use of preceding axis relative to my problem.

My xml looks like

<BOXES>
    <BOX number="1">
         <C name="pencil"/>
         <C name="pen"/>
         <C name="eraser"/>
     </BOX>
     <BOX number="2">
          <C name="pen"/>
          <C name="razor blade"/>
          <C name="highlighter"/>
          <C name="post_it_notes"/>
     </BOX>
     .... other BOXes
</BOXES>

In my xsl i would like to display the names of C in BOX number 2 as "pen_2"
because it's found in
BOX number 2 and there is already a pencil in BOX number 1 (to make the name
unique). For the
pen found in BOX number 1 I just want to display "pen". If the tenth BOX has
a "pen"s also, it should
be displayed as "pen_10" and so forth.
 
so I have a line to check for uniqueness like this:
<xsl:template match="C">
    <xsl:for-each select="C">
        <xsl:choose>
        <xsl:when test="preceding::/*/*/C[@name=current()/@name]">
            <xsl:value-of select="current()/@name"/>_<xsl:value-of
select="../BOX/@number"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="current()/@name"/>
        </xsl:otherwise>
    </xsl:for-each>
</xsl:template>

but this never produces the "_2" in "pen_2".

Any tip?






 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread