[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

difficulties with the position() function and xpath s

Subject: difficulties with the position() function and xpath statements
From: "rick schochler" <ricks@xxxxxxxxxx>
Date: Fri, 2 Nov 2001 13:23:45 -0600
xpath position function
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">&amp;nbsp;</xsl:text>
		<xsl:apply-templates/>
	</xsl:template>


	<xsl:template match="warning">

		<b>WARNING:</b>
		<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
		<xsl:apply-templates/>
	</xsl:template>

</xsl:stylesheet>


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.