[xsl] Starts-with and navigation bar application

Subject: [xsl] Starts-with and navigation bar application
From: "Paul Spence" <paul.spence@xxxxxxxxx>
Date: Mon, 8 Mar 2004 12:35:26 -0000
Hi,

I have developed a system which allows our project partners to control
what appears in the navigation bar of their websites, using a
purpose-built XML file. 

The process involves a collection of XML files (written in TEI XML)
which each has an 'id' attribute whose value I am storing as the
variable '$context_id'.

I process the collection of TEI files, and then access information from
my special homemade navbar XML file in order to decide what to output as
links on the navigation bar. In some pages we may wish to output a
second level of navigation, using something like this:

---------------------------------
My homemade navbar XML contains the following fragment:

<level-1-item>
   <activation ref="doc">
     <level-2-item>

---------------------------------
The XSLT contains the following 'if statement':

   <xsl:for-each
select="document('navbar.xml')//body/layout/level-1-item"> 

      <xsl:if test="activation/@ref=$context_id or
starts-with($context_id, activation/@start)">

        [....then produce a second level of navigation, using
information in <level-2-item> ]

---------------------------------

The central premise is that the <activation> element activates the next
level of navigation. It can use either one of two attributes:
  # 'ref'. If the main TEI XML file's @id matches this, then the next
level is activated.
  # 'start'. The next level of navigation is activated if the TEI XML
file's @id *starts with* this string.

The complication is that there can be more than one <activation> element
(i.e. more than one criteria for opening up the next level of
navigation). So you might say:

"Open up the second level if the main file's @id ...
  ... matches exactly the string 'p3.1'
  ... matches exactly the string 'f3'
  ... starts with the string 'p2'
  ... OR starts with the string 'z'"

The corresponding XML looks roughly like this:

<level-1-item>
   <activation ref="p3.1">
   <activation ref="f3">
   <activation start="p2">
   <activation start="z">
     <level-2-item>

My XSLT works if the multiple <activation> elements all have 'ref'
attributes, but if there are two or more <activation> elements using
'start' attributes (as in the example above), then it only works with
the first one.

I'm guessing that the problem is with the second half of my 'if'
statement, and that it only selects the first <activation> element in
the 'starts-with' function, but I'm not really sure why it does this.

Another doubt is what would happen if that starts-with expression found
two nulls. Can I doctor it to only perform the test if the attribute
'start' actually contains something?

Anyone got any ideas? I am using Saxon 6.5.2 and what I call XSLT 1.1
(it's a long story ...)

Thanks,

Paul Spence
Centre for Computing in the Humanities
King's College London


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread