This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: automatic generation of figure numbers
- To: kcline at grci dot com, XSL-List at mulberrytech dot com
- Subject: RE: automatic generation of figure numbers
- From: "Dhruv Raheja" <dhruv_r at hotmail dot com>
- Date: Wed, 04 Oct 2000 13:21:41 EDT
- Reply-To: xsl-list at mulberrytech dot com
Hello,
Thank you for your mail. I think I need to clarify the "reference"
part of my problem. Below is a sample of my XML code. I apologize for the
clumsy formatting/indenting, basically when I pasted the code into the email
editor, the indenting etc got disturbed.
As you will see below, the <figure> element is interspersed with other
elements. The <figure> element is used wherever I feel the need to insert an
image/picture. I have attempted to highlight the places (in the code) where
the <figure> element is being used so that it is easy for you to spot the
element. I have used the following method to indicate the presence of the
element:
****INSTANCE 1 <figure file="pic.gif">Figure</figure>***** As you can see, I
have inserted *****INSTANCE 1 at the beginning (to indicate the number of
ocurrence) and **** at the end of the element. **** INSTANCE 1 do not form
part of the actual code. I just thought I should clarify that before I
explain the code.
<component type="DC CONTACTOR-41A296327AM" toc2="contactor">
<activity type="FUNCTIONAL DESCRIPTION" toc2="func_desc">
<text_description>
<para>
The Type 41A296327AM DC Contactor
****INSTANCE 1<figure file="one.gif">figure</figure>****** is
a
magnetically operated device used for opening and
closing electrical power circuits. The contactor is
equipped with one stationary and two movable main
contacts. The movable contacts are mounted on an ar-
mature which closes when the operating coil is energized.
Removing power from the operating coil permits
the spring-loaded armature to open and to break the
electrical circuit made by the main contacts.
The contactor can also actuate control circuits
through auxiliary contacts, called interlocks *******INSTANCE
2<figure file="two.gif">Figure</figure>*********. These op-erate in
conjunction with the armature of the contactor.
An arc chute, mounted over the contacts, helps to
extinguish the electrical arc generated when the contac-tor
opens.
</para>
</text_description>
<activity type="INSPECTION" toc2="inspect">
<warning>
<para>
WARNING: To prevent personal injury from elec-trical
shock, turn off power before inspecting the
contactor.
</para>
</warning>
<text_description>
<para>
In general, the inspection schedule for the contactor
should conform to the inspection schedule established
for the vehicle but may be modified, as required, by actual
operating experience. *****INSTANCE 3 <figure
file="three.gif">Figure</figure>*******
The following information is offered as a general inspection
guide which calls attention to what should be
inspected and what to look for when making the inspec-tion.
If the inspection results call for corrective mainte-nance
to be performed, the procedures for carrying out
such maintenance are covered in the MAINTENANCE
section of this publication. *******INSTANCE 4<figure
file="one.gif">Figure</figure>*****
Visually inspect contactor for dirt or contaminants.
Clean contactor if necessary. Check for loose electrical
connections and mounting hardware. Tighten all loose
hardware. Check for worn connecting wires. If wires are
worn, correct the cause of wear and replace wires.
</para>
</text_description>
</activity>
In the code, you will see that each <figure> has a required attribute called
"file" which is used in the XSL code to point to the gif file that a
particular <figure> element refers to, e.g. <figure file =
one.gif>Figure</figure> means that this particular instance of the <figure>
element points to the file "one.gif". Now, the way that XSL formats the
<figure> element is as follows:
XSL converts the text within <figure> to a hyperlink. In addition to that,
it generates a number that it places alongside the text (concatenation)and
it actually hyperlinks the contatenated piece, i.e. for the first instance
of <figure>, it generates a number "1" and appends this to the text of
<figure>. The text of <figure> is "Figure". So the final output is the
hyperlink "Figure 1". This hyperlink points to the file specified by the
attribute "file" e.g. if you click on the hyperlink "Figure 1" in the
output, the file "one.gif" is opened.
How do I generate the number "1"? Well I was using the following code in the
XSL code (similar to what Sebastian suggested):
<xsl:template match="figure">
<xsl:variable name="fig">
<xsl:number level="any"/>
</xsl:variable>
<a>
<xsl:attribute name="href">
<xsl:value-of select="@file"/>
</xsl:attribute>
<xsl:value-of select="."/><xsl:value-of select="$fig"/>
</a>
</xsl:template>
Here the variable "fig" is used to generate the figure number.
However if you see the XML code, there are 4 instances of the <figure>
element as shown
ATTRIBUTE VALUE OF "file" ATTRIBUTE INSTANCE "NO"
FOR DIFFERENT <figure> ELEMENTS
one.gif INSTANCE 1
two.gif INSTANCE 2
three.gif INSTANCE 3
one.gif INSTANCE 4
The first 3 instances have unique/different "file" values, which means that
they point to different image files. However the 4th instance has the same
value for the "file" attribute as the 1st instance. This measn that
somewhere in the document I feel the need to refer to "Figure 1" again ,
i.e. I may have multiple occurences of "Figure 1" in the document. Now my
XSL code generates a new integer for each occurence of <figure>. However
the problem arises when I need "Figure 1" to occur again, i.e. basically I
want the number "1" (or whatever the number might be) to occur again. The
XSL code should somehow compare the "file" value of the current <figure>
element with the "file" values of all the preceding <figure> elements and if
it finds that there is a match (which it will if two <figure> elements point
to the same file), it should assign the same number to the current <figure>
element as it did to the earlier "matching" <figure> element.
I hope I have the problem is clearer now. I would be very grateful if you
could suggest a solution. Thank you very much for you help.
Thanks,
Regards,
Dhruv
>From: "Cline, Ken" <kcline@grci.com>
>To: "'XSL-List@mulberrytech.com'" <XSL-List@mulberrytech.com>
>CC: "'dhruv_r@hotmail.com'" <dhruv_r@hotmail.com>
>Subject: RE: automatic generation of figure numbers
>Date: Wed, 4 Oct 2000 12:02:54 -0400
>
>If I understand your situation, you're trying to DEFINE a figure using the
><figure> element and also to REFERENCE a figure using the same <figure>
>element. If this is true, you're going to have a rough time solving your
>problem.
>
>To refer to a figure that you've DEFINED with a <figure> element, you
>should
>use a different element type (something like <figurereference>) You would
>then have some hope of making it work.
>
>KLC
>----------------------
>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.
>
_________________________________________________________________________
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