I have an xsl-fo document having multiple <page-sequences>
. Every second <page-sequences>
element has the attribute id="end"
. When I reference these IDs with ref-id="end"
, how do I know which element is retrieved? Can I reference the next element having that ID?
Example (my question can be seen again in the comment):
<fo:page-sequence id="end">
...........
</fo:page-sequence>
<fo:page-sequence>
...........
<fo:page-number-citation-last ref-id="end"/>
<!-- unfortunately, the previous element having id="ref" has been thus referenced -->
<!-- how could I reference the next element? -->
...........
</fo:page-sequence>
<fo:page-sequence id="end">
...........
</fo:page-sequence>
Can you please write this as an answer (to both my questions), so that I can accept it?
Sure. The precondition for referring to a specific element in XSL-FO is that you have a means of identifying it unambiguously. The best way to do this is to use an ID
attribute for the element you wish to identify.
An ID must consist of any sequence of alphanumerical characters and _
(that is, its value must be a valid NCName, see the specification here).
You can type out each ID by hand, but normally this is done with xsl:generate-id()
(wich is a function of XSLT, not XSL-FO). generate-id()
automatically ensures that the IDs are unique throughout a document.
Note that generate-id()
actually generates an ID for either the current template match or the node that is being processed in an iteration of xsl:for-each
.
You can put an ID on every element in XML and referring to something by ID is therefore possible for any element in XSL-FO.