xsl-list
[Top] [All Lists]

RE: Pick up generated numbering for cross reference using key?

2005-03-22 06:21:44
Keys apply to any document, including a temporary document created in a
variable. You don't need to indicate in the xsl:key declaration which
document they are intended to be used with, they automatically apply to the
document that contains the context node at the time you call the key()
function.

What you are essentially suggesting here is doing a two-phase transformation
in which the section numbers are generated during the first phase, and the
cross-references are filled in during the second phase. That's a perfectly
reasonable design approach, but you haven't convinced me that it's
necessary. If the number of a table can be computed by examining where the
table is in the source document, then you can use the approach of
recalculating the number each time you process a cross-reference.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Cas Tuyn [mailto:Cas(_dot_)Tuyn(_at_)asml(_dot_)com] 
Sent: 22 March 2005 13:14
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Pick up generated numbering for cross 
reference using key?

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.


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--