Subject: Re: [xsl] Numbered references From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Wed, 19 Dec 2001 14:36:47 +0000 |
Hi Adriano, > It works. But my question is how do I generate the label (number) in > a cross-reference? In the text, I use > > <figref id="fig:two/> > > which I would like to translate to > > Fig. 2 > > in the output. But I cannot figure how to generate again the number > from outside the context provided by the element figure. It is > probably easy, but I just don't see how. To generate the number with xsl:number, you need to make sure that the current node is the relevant figure element. That means first finding the figure element, and then using it to generate the number. To find the figure element, you need to take the figref's id attribute and find the figure whose id attribute has the same value. I'd do this by setting up a key to index the figure elements by their id: <xsl:key name="figures" match="figure" use="@id" /> And then using the key() function to retrieve the figure with a particular ID. For example, to get the figure element whose id attribute has the value 'fig:two', you can use: key('figures', 'fig:two') You can make this figure element the current node using an xsl:for-each (just as a way of changing context), and putting the xsl:number instruction within that xsl:for-each: <xsl:for-each select="key('figures', 'fig:two')"> <xsl:number level="any" format="1 " /> </xsl:for-each> Alternatively, you could set up a template that matches figure elements in 'label' mode and generates the figure label, which you use in both the main output for the figure and in the output for the figure reference. For example: <xsl:template match="figure" mode="label"> Fig. <xsl:number level="any" format="1 " /> </xsl:template> You could then apply templates to the figure element in label mode when you wanted to get that label while processing the figref element: <xsl:apply-templates select="key('figures', 'fig:two')" mode="label" /> A couple of notes: If the id attribute on the figure element were an ID attribute, you could use the id() function instead of the key. If the id attributes hold qualified names (as it looks they might do), then you should instead index the figure elements by an extended representation of the qualified name, using the namespace rather than the prefix (e.g. '{http://www.example.com/figures}two' rather than 'fig:two'), and similarly retrieve them using the namespace resolved to by the prefix used in the figref. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Numbered references, Adriano Rodrigues Fe | Thread | Re: [xsl] Numbered references, David Carlisle |
[xsl] One nodeset, multiple branche, Eric Vitiello | Date | Re: [xsl] Numbered references, David Carlisle |
Month |