[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: "remembering" variable values

Subject: RE: "remembering" variable values
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Wed, 27 Sep 2000 18:00:31 +0100
remembering cubed numbers
> [snip]... 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"/>

Fine so far; though you could also use
<xsl:variable name="fig"><xsl:number level="any"/></xsl:variable> which some
processors might execute faster.

> 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". ... 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?

What you are saying is, when you encounter <fig ref="xyz.gif"/>, you want to
output the number of the first figure having that ref value; and for good
measure, you don't want to increment the figure number for this one.

You can achieve the first part by writing
<xsl:variable name="fig">
<xsl:for-each select="//figure[@ref=current()/@ref][1]">
<xsl:number level="any"/>
</xsl:for-each>
</xsl:variable>

(The xsl:for-each here is not to process a set of things, it is to change
the current node, because xsl:number only works on the current node)

And you can achieve the second part by changing the xsl:number to

<xsl:number level="any" count="figure[not(@ref=preceding::figure/@ref)]"/>

I have to admit, though, that the performance of this is likely to be
horrendous. For each figure, it is likely to look for each of the preceding
figures, and for each preceding figure, it will look to see if there is a
previous one with the same ref attribute. That's n-cubed performance. If you
want to improve this, the way forward is probably to define an xsl:key, but
I won't explore that.
> 
> 2.) ... 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?
> 
To do this you need to generate multiple output files. This extension is
available in many of the currently-available XSLT processors.

Mike Kay


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.