Re: Matching in IDREFS attributes

Subject: Re: Matching in IDREFS attributes
From: "Pete Johnston" <P.Johnston@xxxxxxxxxxxxxxxxxx>
Date: Fri, 16 Jul 1999 12:33:45 GMT
[Jean Daniel Fekete]

> I have XML elements with an ANA attribute of type IDREFS.  I want to
> iterate over these refs in XSL and create an hypertext link to each
> referenced id.

There really _must_ be a better solution than this but I think a 
called template working its way through the value of the attribute as 
a string does the trick... something like:

<xsl:template match="name">

<xsl:value-of select="."/>

<xsl:call-template name="get-ref">
<xsl:param name="refstring" expr="@ana"/>


<xsl:template name="get-ref">
<xsl:param-variable name="refstring"/>
<xsl:param-variable name="count" expr="1"/>

<xsl:variable name="thisref"
expr="substring-before(concat($refstring,' '),' ')"/>

<xsl:if test="not($thisref='')">

<xsl:element name="a">
<xsl:attribute name="href">#<xsl:value-of select="$thisref"/>
<xsl:value-of select="$count"/>

<xsl:call-template name="get-ref">
<xsl:param name="refstring" expr="substring-after($refstring,' ')"/>
<xsl:param name="count" expr="$count+1"/> 



> 2nd problem, probably harder: I would also like to have a two-way
> linking where the <INTERP ...> points back to all its references.

I haven't worked this through fully, but if all the references are 
in "ana" attributes then I think a pattern something like the 
following might help:

<xsl:template match="interp">

<xsl:variable name="thisid" expr="@id"/>

<xsl:for-each select="//*[contains(concat' ',(@ana,' '),concat(' 
',$thisid,' '))]">

[process referring elements to generate link back]



Pete Johnston
University of Glasgow

 XSL-List info and archive:

Current Thread