[Techtalk] [LONG] xslt and xpath

David Merrill david at lupercalia.net
Tue Sep 18 11:59:31 EST 2001


I'm having an xslt problem. I am working with xml files from
scrollkeeper (http://scrollkeeper.www.sourceforge.net).

I have an xml file that looks like this:


<?xml version="1.0"?>
<ScrollKeeperContentsList>
  <sect>
    <title>Applications</title>
    <sect>
      <title>Amusement</title>
    </sect>
  <sect>
    <title>Other</title>
    <sect>
      <title>Other</title>
      <doc docid="1">
        <doctitle>ScrollKeeper Example Package 1 Manual</doctitle>
        <docomf>/usr/share/omf/scrollkeeper-example1/scrollkeeper-example1-manual-C.omf</docomf>
        <docsource>/usr/share/scrollkeeper-example1/doc/scrollkeeper-example1-manual/C/scrollkeeper-example1-manual.sgml</docsource>
        <docformat>text/sgml</docformat>
      </doc>
    </sect>
  </sect>
</ScrollKeeperContentsList>

and I want to only run templates for <sect> if they have descendent
<doc> elements. I've read a couple of tutorials on xpath expressions
but I must be missing something because it's not working for me.

By the way I'm running xsltproc and libxml.

Here's my stylesheet:


<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:template match="text()">
<!--  <xsl:value-of select="."/> -->
</xsl:template>

<xsl:template match="ScrollKeeperContentsList">
  <h1>
  <xsl:value-of select="title"/>
  </h1>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="ScrollKeeperContentsList/sect[//doc]">
  <h1>
  <xsl:value-of select="title"/>
  </h1>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="ScrollKeeperContentsList/sect/sect[//doc]">
  <h2>
  <xsl:value-of select="title"/>
  </h2>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="doc">
  <a href="docid?{@docid}">
  <xsl:value-of select="doctitle"/></a>
  <br></br>
</xsl:template>

<xsl:template match="/">
  <html>
  <head>
    <title>ScrollServer</title>  
  </head>
  <body>
    <p>
      <a href="/index.html">Index</a>
    </p>
    <xsl:apply-templates/>
  </body>
  </html>
</xsl:template>

<!-- ==================================================================== -->

</xsl:stylesheet>


Does anyone see the problem?


-- 
Dr. David C. Merrill                     http://www.lupercalia.net
Linux Documentation Project                   david at lupercalia.net
Collection Editor & Coordinator            http://www.linuxdoc.org




More information about the Techtalk mailing list