Re: [xsl] hyperlink

Subject: Re: [xsl] hyperlink
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Jul 2001 09:27:19 +0100
Hi Paul,

> I have an xml file linked to an xsl sheet and a schema. I'm having
> trouble linking a column of table data. The column contains project
> titles which, I would like to link to their respective descriptions.
> The table has multiple headers which, when clicked, sort the
> corresponding column of data. I can't figure out how to make a
> different link for each piece of data in the "project title" column.
> I'm hoping I don't have to use xlink, as I am barely figuring out
> xsl hehe. The following is the section of the xsl sheet I am
> referring to, then the xml file. Thank you for any help.

As I understand it, the bit you're having problems with is in trying
to create a link from the table, which contains the names of the
projects, to a description about each project. You don't say where
this description resides - perhaps you want a pop-up box, perhaps it's
further down the page, perhaps it has its own page? I'll assume that
it's further down the same page for now.

In any case, to do it you need a unique ID for each project that you
can use as the anchor for the project description, which you then link
to. There are several things that you could use for the unique ID for
the project:

 * the project title, normalized and with spaces replaced by hyphens
   or underscores

     translate(normalize-space(project_title), ' ', '_')

 * the position of the project in the list, prefixed by some letters
   to create a valid ID

     concat('proj', count(preceding-sibling::project))

 * a generated ID for the project using generate-id()


These each have advantages and disadvantages. The first two will stay
the same every time you perform the transformation, whereas the
generated ID might change. The project titles may not be unique -
that's something you have to check in your source - and are fairly
long. The position of the project takes a long time to calculate.

Taking the last option, you need to create a link that uses this ID
within the table cell holding the project title:

    <div class="row">
      <a href="#{generate-id()}">
        <xsl:value-of select="project_title" />

and create an anchor for the project when you give its description
further down the page, which probably looks something like:

<xsl:template match="project">
    <a name="{generate-id()}" id="{generate-id()}">
      <xsl:value-of select="project_title" />
  <xsl:apply-templates select="description" />

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread