Re: [xsl] Question about linking using ID/IDREF

Subject: Re: [xsl] Question about linking using ID/IDREF
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Apr 2001 19:34:26 +0100
Hi Betty,

> The text is defined with <refint> using an attribute of "refid" to
> link to the attribute of "id". I read earlier that I needed to use
> the XSLT style in conjunction with a DTD. I used XMLSPY to
> auto-generate a DTD.

It's true that if you use the id() function then you have to have a
DTD to indicate that the attribute you want to use as an id is an ID
attribute.  However, you can have the same functionality using the
key() function instead.  So in your case, you could do:

<xsl:key name="tasks" match="task" use="@id" />

and then do:

<xsl:template match="para/refint">
  <font color="blue">
      <a href="#{@refid}">
         <xsl:value-of select="key('task', @refid)"/>
         <xsl:value-of select="."/>

Note that in the above I've used an attribute value template rather
than an xsl:attribute element to create the href attribute.

> Once I got my coding in place, I tried to view this data in IE5.5
> but it doesn't seem to work. When I place my cursor over the link,
> in the info-line at the bottom of IE5.5 I see,
> file:///c:/bjdir/amm/chap07.xml#T07-10-00-500-801-A.

When IE gets given the above URL, it goes off and finds chap07.xml.
It then looks at that file to try to find an xml-stylesheet processing
instruction to indicate an XSLT stylesheet that it should apply.

If it doesn't find one, then it displays the XML in the 'tree view'
that IE uses, and it jumps to the relevant element within that XML, so
it'll jump to the task with the ID that you give after the #.

If it *does* find an XSLT stylesheet to apply, on the other hand, then
it will apply it first, and then try to find the anchor (or id)
*within the resulting HTML* and jump to that point of the HTML

So, if you're transforming the XML to HTML, then you also need to have
something that creates an anchor or an id-ed element within the HTML
for the tasks that you want to jump to, something like:

<xsl:template match="task">
   <h2 id="{@id}"><xsl:apply-templates select="title" /></h2>

What IE *doesn't* do is retrieve the XML file, and then *only* display
the relevant element, and it also doesn't only transform the relevant
element.  IE only uses the fragment to jump to a point in whatever it
would normally display for the entire document.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread