[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Generating numbering for cross-references (LONG)
Subject: Re: [xsl] Generating numbering for cross-references (LONG) From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx> Date: Thu, 18 Oct 2001 11:29:44 -0400 |
[Peter Flynn] > This has foxed numerous brains, including three of the co-authors of > XSL and XPath. I hope it's not just my clumsy way of expressing it. > > 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"> > [...] > What I find unbelievable is that no-one has yet done this. It must be > one of the most common requirements in document processing, and > without it, XSLT simply cannot be used to reproduce simple numeric > cross-references like "see Figure 16" or <plug>bibliographic > references like Kay[23]</plug> :-) > > What have I missed? > You could approach this by creating a key that matches generate-id() of the elements you are interested in (the ones with the ID attributes, I guess) and returns the corresponding node. Then you could create a variable containing a list of those kind of nodes. In processing, when you get to that kind of element, identify it by generate-id(), use the key to get its node or parent node or whatever, then call a named template on it to create the reference number (table number, etc.) that you want, passing the node in as a parameter. When you do this, calling position() on the context node will in fact give its position in the list of similar nodes, which is what you want to construct your figure or section numbers. You could do this on a chapter-by-chapter basis if you wanted to. You mentioned > Youcannot reach over to the relevant part of the tree (by ID) and > pluck a copy of a number which has not yet been generated. But in fact the position of all the nodes is established before processing of the stylesheet is started, when the document tree was build. So you can use that position anywhere in the stylesheet, if you if you don't think too sequentially. If you use a processor like Saxon or XALAN that lets you convert result tree fragments to node-sets, you actually could build up your numbers and insert them where you want. Bear in mind that "before" in xslt processing generally means earlier in a sequence of recursions, or earlier in a list of nodes, but not necessarily "earlier" in the list of templates in the stylesheet. You actually don't know in what order the various templates might get processed. You can only know something about their precedence or dependency. Another approach would be to use two passes - one stylesheet to insert the numbers and one to identify where they should go. I know this is fairly general, but you asked about a general topic. I'm not saying it would be easy, though. Cheers, Tom P XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Generating numbering for , G. Ken Holman | Thread | Re: [xsl] Generating numbering for , Wendell Piez |
Re: [xsl] Passing in parameter used, Jeni Tennison | Date | [xsl] Problems switching from Xalan, Mark Burmei |
Month |