automatic generation of figure numbers

Subject: automatic generation of figure numbers
From: "Dhruv Raheja" <dhruv_r@xxxxxxxxxxx>
Date: Tue, 03 Oct 2000 15:16:54 EDT
Hello All,
I have this problem for sometime now but I am unable to solve it. I am hoping somebody on the list will be able to guide me. I have the following element in my code:


<figure file="pic.gif">
Figure
</figure>

The formatting is being done using XSL. The output should comprise:

-the text "Figure"
-a number (e.g. "1").

Thus the actual output is "Figure 1". The number portion of the output is to be generated automatically by XSL. I have several <figure> elements in the document for refering to different figures. The XSL code has a "count()" command that counts the preceding <figure> elements and then assigns the next number to the current <figure> element. My problem is that I may have more than I references to the same figure. i.e. lets say I want have "Figure 1" more than once in the document. I use <figure file="pic.gif"> Figure </figure> for the first occurence of Figure 1 and the XSL code generates the output "Figure 1". I then subsequently have several <figure> elements for different figures and XSL accordingly assigns a number for each <figure> element, e.g. "Figure 2", "Figure 3" etc. Then I feel the need to refer back to "Figure 1". This is what is causing a problem. How do I tell XSL to stop counting at this point and assign the same figure number as for "Figure 1". One solution was that every time XSL sees the <figure> element, it compares the attribute "file" of the current <figure> element to the "file" attribute of all the previous <figure> elements. If it finds any match (which it will if the same figure is being referenced again), it should stop the count and assign the same number to this element.
Mike Kay suggested (I am thankful to him for that) the following code:


<xsl:template match="figure">
<xsl:variable name="fig"><!--variable for the figure number-->
<xsl:for-each select="//figure[@file=current()/@file[1]">
<xsl:number level="any" count="figure[not(@file=preceding::file/@file)]"/>
</xsl:for-each>
</xsl:variable>
</xsl:template>


Unfortunately, the code doesnt work completely. Although XSL is able to identify those <figure> elements that have the same "file" attribute and assign them the same number, the number it generates is arbitrary (not the desired number). Also Mike, I am unable to follow logic of the code (which is entirely my shortcoming). Could you/anybody else explain it to me and also suggest any modifications that need to be made to it for the code to work?
I am really hoping that someone will be able to help.
If the problem is not clear, I would be happy to explain the "blurred" points again through email/phone.


Thanks a lot,
Regards,
Dhruv
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at http://profiles.msn.com.


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



Current Thread