[xsl] Pick up generated numbering for cross reference using key?

Subject: [xsl] Pick up generated numbering for cross reference using key?
From: "Cas Tuyn" <Cas.Tuyn@xxxxxxxx>
Date: Tue, 22 Mar 2005 14:13:54 +0100
Hi,

My tables have double-digit numbering generated from the section number
as a variable, and the calculated sequence inside the section:

<xsl:template match="table">
	<xsl:param name="secnum" />
	<xsl:variable name="tabnum">
		<xsl:value-of select="count(preceding::table)+1" />
	</xsl:variable>
... lines left out ...
	<caption>
		Table <xsl:value-of select="$secnum" />.<xsl:value-of
select="$tabnum" /> <xsl:value-of select="title" />
	</caption>
</xsl:template>

This works good. Now I'm trying to make cross references to those
tables. I've searched the xsl archives and found a 2001 thread where it
was suggested to either calculate it again (impossible because of the
section-part being a variable), or store it in a key value. The latter
method reminds me of arrays in other languages, so I thought it was the
right direction.

Using the 'XSLT programmers reference' it appears that:
1. you can only use xsl:key immediately under the root of the document,
2. put existing text or attribute values (not generated) in there.

I was hoping to insert:
	<xsl:key name="table-number" match="@id" use="$secnum . $tabnum"
/>
immediately below the variable definition shown above, but that returned
"Unexpected child" due to rule #1 not observed.

The XML code for origin and target of the link:
	<xref role="table" linkend="csrh026a.dia-6"/>
	<table id="csrh026a.dia-6">

The XSLT for the origin of the link:
	<xsl:template match="xref">
		<xsl:for-each select="@linkend">
			<xsl:variable name="linkend" select="."/>
			<xsl:element name="a">
				<xsl:attribute
name="href">#<xsl:value-of select="."/></xsl:attribute>
				<xsl:for-each select="../@role">
					<xsl:choose>
						<xsl:when
test="(.='table')">
							table x.x
						</xsl:when>
					</xsl:choose>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	</xsl:template>

The "x.x" should be the number of the table where I refer too.

Questions:
 1. Is this a good way of doing this?
 2. Is there a better way using XSLT 1.0

Regards,

Cas




--
The information contained in this communication and any attachments is
confidential and may be privileged, and is for the sole use of the intended
recipient(s). Any unauthorized review, use, disclosure or distribution is
prohibited. If you are not the intended recipient, please notify the sender
immediately by replying to this message and destroy all copies of this message
and any attachments. ASML is neither liable for the proper and complete
transmission of the information contained in this communication, nor for any
delay in its receipt.

Current Thread