Re: [xsl] following-sibling problem

Subject: Re: [xsl] following-sibling problem
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Tue, 2 Nov 2004 10:46:57 -0500
Thanks Joe,

On Nov 2, 2004, at 10:28 AM, Joe Heidenreich wrote:

It seems the reason your process-level isn't returning any <li> tags
is because there isn't a level 3. What's happening is you are
outputting the <ul> before checking to see whether there is a value.

Yes, I should have made clear that I know I needed a test, but just didn't know *how* to do it.

Alas the below doesn't quite work.  Besides needing to change the "<"
to "&lt;", my level 2 bullets aren't getting applied now.

I think what you want to do is check to see if:

<xsl:if test="@level < following-sibling::bullet[@level][1]">
	<ul>
		<xsl:apply-templates/> <-- You'll have to edit this
	</ul>
</xsl>

Here's the complete stylesheet:


===
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version='2.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
	xmlns:key="http://developer.apple.com/schemas/APXL";
	xmlns:xs="http://www.w3.org/2001/XMLSchema";
	xmlns="http://www.w3.org/1999/xhtml";
	xmlns:xhtml="http://www.w3.org/1999/xhtml";
	exclude-result-prefixes="key xhtml">
<!--
A simple XSLT convert Apple Keynote presentation files to S5, the
XHTML-based
slideshow system from Eric Meyer.

Because of limitations in the Keynote file format, I have relied on the
new
grouping functionality in XSLT 2.0. As such, you should use Saxon 8 to
run it.
-->

<xsl:output method="xhtml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="venue"/>
<xsl:variable name="title"
	select="//key:slide[@master-slide-id='master-slide-1']/key:bullets/
key:bullet[@level='0']"/>
<xsl:variable name="author">Bruce DArcus</xsl:variable>
<xsl:template match="/">
  <html>
    <head>
      <title>
	<xsl:value-of select="$title"/>
      </title>
      <link rel="stylesheet" href="ui/slides.css" type="text/css"
media="screen" id="slideProj" />
      <link rel="stylesheet" href="ui/opera.css" type="text/css"
media="projection" id="operaFix" />
      <link rel="stylesheet" href="ui/print.css" type="text/css"
media="print" id="slidePrint" />
      <script src="ui/slides.js" type="text/javascript"></script>
    </head>
    <body>
      <div class="layout">
        <div id="currentSlide"><xsl:text>&#x0020;</xsl:text></div>
        <div id="header"><xsl:text>&#x0020;</xsl:text></div>
        <div id="footer">
          <h1><xsl:value-of select="$venue"/></h1>
          <h2><xsl:value-of select="$title"/></h2>
          <div id="controls"><xsl:text>&#x0020;</xsl:text></div>
         </div>
      </div>

      <div class="presentation">
        <xsl:apply-templates select="//key:slide"/>
      </div>
    </body>
  </html>
</xsl:template>


<xsl:template match="key:slide"> <div class="slide"> <xsl:apply-templates select="key:bullets"/> <xsl:apply-templates select="key:drawables/key:image[contains(@image-data, '.jpg')]| key:drawables/key:image[contains(@image-data, '.png')]"/> </div> </xsl:template>

<xsl:template match="key:bullets">
  <xsl:choose>
    <xsl:when test="../@master-slide-id='master-slide-1'">
      <xsl:apply-templates select="key:bullet[@level='0']"
mode="title"/>
    </xsl:when>
    <xsl:otherwise>
      <h2><xsl:value-of select="key:bullet[@level='0']"/></h2>
      <ul>
        <xsl:call-template name="process-level">
          <xsl:with-param name="bullet" select="key:bullet"/>
          <xsl:with-param name="level" select="1"/>
        </xsl:call-template>
      </ul>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="key:drawables/key:image[contains(@image-data,
'.jpg')]|
		key:drawables/key:image[contains(@image-data, '.png')]">
  <div class="image">
    <img src="{@image-data}"/>
  </div>
</xsl:template>

<xsl:template match="key:bullet[@level='0']" mode="title">
  <h1><xsl:value-of select="$title"/></h1>
  <h3><xsl:value-of select="$author"/></h3>
</xsl:template>

<xsl:template name="process-level">
  <xsl:param name="bullet" required="yes" as="element()*"/>
  <xsl:param name="level" required="yes" as="xs:integer"/>
  <xsl:for-each-group select="$bullet[not(@level='0')]"
                group-starting-with="*[xs:integer(@level) eq $level]">
      <li><xsl:value-of select="normalize-space(.)"/>
 	<xsl:if test="@level &lt; following-sibling::bullet[@level][1]">
          <ul>
            <xsl:call-template name="process-level">
              <xsl:with-param name="bullet" select="current-group()
except ."/>
              <xsl:with-param name="level" select="$level + 1"/>
            </xsl:call-template>
          </ul>
	</xsl:if>
      </li>
  </xsl:for-each-group>
</xsl:template>

</xsl:stylesheet>
===

Bruce

Current Thread