| Subject: Re: [xsl] built in templates question From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 16 Aug 2002 12:39:28 +0100 | 
Hi Brian,
Note that in:
>   <heading2>
>     Course Information
>     <sub resource="Geo101_readings.doc">Reading
> List</sub>
>     <sub
> resource="Geo101_syllabus2.doc">Syllabus</sub>
>     <sub resource="Geo101_schedule.doc">Schedule</sub>
>   </heading2>
for example, the heading2 element contains a text node with the
(normalised) value "Course Information" and three child sub elements
that have their own text nodes.
When you get the string value of a node, for example by doing:
  <xsl:value-of select="." />
you get a string that's made by concatenating all the text node
*descendants* of the node (not only the children). For example, the
string value of the heading2 element above is (ignoring whitespace
issues):
  "Course Information Reading List Syllabus Schedule"
You're not interested in that string value; instead, you want the
value of the text node child of the node, so you want:
  <xsl:value-of select="text()" />
[If you can, I'd advise you change your XML so that, aside from
elements that have to contain mixed content because they contain
documentation, all your elements either contain *only* other elements
or *only* text. For example, use:
  <heading2>
    <title>Course Information</title>
    <sub resource="Geo101_readings.doc">Reading List</sub>
    <sub resource="Geo101_syllabus2.doc">Syllabus</sub>
    <sub resource="Geo101_schedule.doc">Schedule</sub>
  </heading2>
instead. That way you can use:
  <xsl:value-of select="title" />
and it's a lot clearer what piece of information you're pulling out.]
So your templates need to look like:
<xsl:template match="heading2">
  <xsl:choose>
    <xsl:when test = "@resource">
      <a href="{@resource}">
        <xsl:value-of select="text()"/>
      </a>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="text()"/><br/>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:apply-templates select="heading3"/>
  <xsl:apply-templates select="sub"/>
</xsl:template>
> Also, I would like to be able to present the output in the form of a
> navigation menu where the sub elements could be contained in a
> folder, which would open when clicked on, which I assume would
> involve using javascript. I haven't used js before so any advice on
> how I should approach this would also be appreciated.
Others might be able to give you more specific guidance, but a quick
Google search shows a proliferation of JavaScript navigation menus
available at http://www.sitenavigation.net/. Just bear in mind that
your XSLT will be constructing the JavaScript, which is just text as
far as it is concerned -- I recommend you create the HTML page with
JavaScript inside it first, and then work out how to create XSLT to
create that HTML page from your XML.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
| Current Thread | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| [xsl] built in templates question, Brian Hickey | Thread | [xsl] does an element have a unique, Thomas Sandor | 
| [xsl] does an element have a unique, Thomas Sandor | Date | Re: [xsl] does an element have a un, Jeni Tennison | 
| Month |