This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
difficulties with the position() function and xpath statements
- To: <XSL-List at lists dot mulberrytech dot com>
- Subject: [xsl] difficulties with the position() function and xpath statements
- From: "rick schochler" <ricks at isogen dot com>
- Date: Fri, 2 Nov 2001 13:23:45 -0600
- Reply-To: xsl-list at lists dot mulberrytech dot com
Thanks in advance for any assistance.
I need to output multiple .html files from my source xml document. In a
nutshell, whenever I have a section element, I need a semantically unique
html page to be created. In addition, I need to create tables of contents
both at the top level and within sections.
constraints:
1. Section elements are recursive (i.e., sections can contain sections).
2. I cannot count on ids being present.
3. I must render elements in the order that they appear in the source
document.
I am using saxon and <xsl:document> to accomplish the creation of html
files. In order for these files to be semantically different, I'm using the
position function in my name: <xsl:document
href="section{position()}.html">. I also use this same statement when
creating my tocs (a href="section{position()}.html). However, I get two
different numbers assigned (and thus my html links don't work). Any ideas
on how to get around this? I've included a simple example below.
note: i've tried to use <xsl:number> in my name via a parameter: <a
href="{concat('section', $number, '.html')}">; however, <xsl:number>
doesn't appear to increment.
Secondly, and also in the examples below, it appears that I'm getting a
conflict between the template for "manual/section" and
"manual/section/section"...I've tried "massaging" the xpath statement in
several different ways but nothing seems to work.
examples:
xml file:
<manual>
<title>Instruction Manual</title>
<overview><para>content</para></overview>
<section>
<title>Section 1</title>
<overview>content</overview>
<para>section content</para>
<note>Note Information</note>
<para>More section content.</para>
<section>
<title>Subsection 1</title>
<overview>content</overview>
<para>subsection content</para>
<warning>Warning content</warning>
<para>More para content</para>
</section>
</section>
<section>
<title>Section 2</title>
<overview>content</overview>
<para>section content</para>
<section>
<title>Subsection 1</title>
<overview>content</overview>
<para>subsection content</para>
</section>
</section>
</manual>
xsl file:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="manual">
<xsl:document href="manual.html">
<h1><xsl:value-of select="title"/></h1>
<xsl:apply-templates select="overview"/>
<xsl:for-each select="section">
<xsl:document href="section{position()}.html">
<xsl:apply-templates/>
</xsl:document>
</xsl:for-each>
<!-- manual-level toc generation -->
<p class="Body">This document provides information about the following
topics:</p>
<ul type="disc">
<xsl:for-each select="section">
<li>
<a href="section{position()}.html">
<xsl:value-of select="title"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:document>
</xsl:template>
<xsl:template match="manual/section">
<!-- Must use apply-templates here as xslt must handle elements in order
of occurence. -->
<xsl:apply-templates/>
<!-- section-level toc generation -->
<p class="Body">This document provides information about the following
topics:</p>
<ul type="disc">
<xsl:for-each select="section">
<li>
<a href="subsection{position()}.html">
<xsl:value-of select="title"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template match="manual/section/section">
<xsl:document href="subsection{position()}.html">
<xsl:apply-templates/>
</xsl:document>
</xsl:template>
<xsl:template match="section/title">
<h1>
<xsl:apply-templates/>
</h1>
</xsl:template>
<xsl:template match="overview">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="para">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="note">
<b>NOTE:</b>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="warning">
<b>WARNING:</b>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list