This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Generating numbering for cross-references (LONG)
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Generating numbering for cross-references (LONG)
- From: Wendell Piez <wapiez at mulberrytech dot com>
- Date: Thu, 18 Oct 2001 12:32:52 -0400
- Reply-To: xsl-list at lists dot mulberrytech dot com
Peter,
What about something like:
<xsl:template match="ref">
<xsl:apply-templates select="id(@to)" mode="ref-label"/>
</xsl:template>
<xsl:template match="section" mode="ref-label">
<xsl:text>Section </xsl:text>
<xsl:number level="multiple" format="1.1.1"/>
</xsl:template>
and so forth?
For many cases, a for-each could also be used to change context and
generate the number, instead of a call to another template with a mode.
Cheers,
Wendell
At 09:06 PM 10/17/01, you wrote:
>In a typical research document, an author needs to make many
>cross-references. XML provides ID and IDREF attributes for this
>purpose, and lots of DTDs are written to make use of them. I'm having
>a problem instatiating three classes of numeric cross-reference in
>XSLT, namely:
>
>a. Tables and figures, as in `See <ref to="foo"/>' where
> you have <table id="foo"> or <figure id="foo">
>
>b. Chapters/sections/subsections/etc, where the reference
> looks the same as above but points at (eg) <section id="foo">
> and needs to generate a decimal-style reference (eg 1.1.1)
>
>c. Reading lists (bibliographies) where the citation says
> <cite work="foo"/> and the entry says <bibentry id="foo">
>
>In normal processing of the document text, you use <xsl:number> to
>assign counters to tables, figures, chapters, sections, bib entries,
>etc. At serialization, these numbers get values in the normal way,
>but those values are not available or accessible to other places
>in the stylesheet because the language is side-effect free. You
>cannot reach over to the relevant part of the tree (by ID) and
>pluck a copy of a number which has not yet been generated.
That's serial thinking: let the processor go ahead and do it!
>********************************************************************
>At the point where a reference is made, what is the XPath expression
>you need to generate the number which will be the value which will
>eventually get assigned to the target?
>********************************************************************
Why use XPath? it's for traversing trees. Using it to generate numbers for
our output is just something we do to enhance processing, when our case is
simple enough not to be worth the overhead of <xsl:number/>.
>References can be scattered (randomly distributed) through the
>document, so <xsl:number> cannot be used at the point of reference as
>it can be at the target, as it presupposes sequence.
Not so. It's performance is poor precisely because it does not presuppose
sequence of processing, only that the original document has an order.
I think your XPath is trying to reimplement xsl:number, which is unnecessary.
Or have *I* missed something? (I do this kind of cross-referencing all the
time. :-).
Cheers,
Wendell
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list