"remembering" variable values

Subject: "remembering" variable values
From: "Dhruv Raheja" <dhruv_r@xxxxxxxxxxx>
Date: Wed, 27 Sep 2000 09:45:58 EDT
Hello All,
Thanks a lot especially to Ben and Mike for helping me with my problem. I have managed to solve part of the problem. In order to make the problem a little clearer (as Mike suggested), I'll try and explain it again.


I am in the process of preparing XML/DTD/XSL data models for authoring technical manuals for my company's products. The manuals contain both text and images in a particular structure. The present system of authoring makes use of Interleaf (a UNIX-based publishing tool). The problem has to do with incorporating a function of Interleaf in XML. Interleaf has a way of automatically assigning numbers to figures e.g. Figure 1, Figure 2. Here the numbers are assigned automatically (without the author having to worry about numbering). The advantage is that if, after completing the document, the author needs to insert another image somewhere in the document, she can do that without having to worry about re-numbering the images/figures that follow the inserted figure, Interleaf will take care of that. The technical writers that I am working with, want me to do that in XML.
Earlier I had an element called <figure>, in which I hard-coded the figure number, i.e. in the XML document I had the following:
<figure type="file.gif">
Figure 1
</figure>
Here the XSL code is such that it converts "Figure 1" to a hyperlink and links it to the file specified in the "type" atttribute and opens the gif file in another browser window.
I was subsequently asked to find a way to automate the assignment of the figure number.
Hence I thought that one way could be that instead of having "Figure 1" as the text of <figure>, I have only "Figure" and I somehow generate the figure number using an XPath expression.
Thus the new content of figure is:
<figure>
Figure
</figure>


My XSL code is as follows:

<xsl:template match="figure">
<!--Creating a variable and assigning a value to it-->
<xsl:variable name="fig" select="count(preceding::figure) + 1"/>
<a>
<xsl:attribute name="ahref">
<xsl:value-of select="@type">
</xsl:attribute>
<!--Specifying that the gif file is to be opened in another browser window-->
<xsl:attribute name="target">
_new
</xsl:attribute>
(<xsl:value-of select="."/>_<xsl:value-of select="$fig">)
</a>


The XPath expression in the third line of the XSL code, counts the number of <figure> elements before the current figure element and adds 1 to the result and assigns that value to the variable :fig". The variable is then displayed along with the text "Figure.
The result is that the following output is produced:
(Figure_1)
which is hyperlinked and points to the gif file.
Now, my problems are as follows:


1.) The above method, in a way, automates the process. But there is a flaw in this. Suppose that a particular figure is referenced more than once in the document. e.g. lets say that I want to refer to "Figure 1" again, after say "Figure 2". That is not possible through this method because the code will generates the next number in the sequence every time it sees a <figure> element. Is there any way once a generate a particular number for a figure, I somehow establish a relation between the gif file that it points to and the number so that if the code comes across the same attribute value (i.e. the gif file) again in the document, it generates the corresponding number for that, instead of generating a new number?

2.) As I showed above, I am opening the gif file in another browser window using the ahref target="_new" functionality. I want to append the gif file with a caption like "Figure 1: Description". So in order to do that, I will create a new element called <caption> and again use the value of the "fig" variable to create the caption. However, how do I append this element to the gif file and subsequently display the combined result (the gif file and the <caption>) in another browser window?

I hope this explanation is better than my earlier one. If it isnt I apologize. In case you need a better explanation or any clarifications, please let me know.

Thank you very much for your time and effort,
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