[xsl] more nesting node questions

Subject: [xsl] more nesting node questions
From: Andy <achall@xxxxxxxxx>
Date: Thu, 26 May 2005 15:47:07 -0400
Hello,

I have been trying to figure out a problem for a couple of days now.

Here's the situation:
I have a list of steps. A step contains one command element followed
by one or more notes and/or para elements.

My XSL can get the info from the elements and the retain the order of
the elements just fine. What I have not managed to do is lay them out
on separate lines.

I am trying to render the data as plain text. I am using Saxon 6.5.3
and XSLT 1.0.

This is what I don't want and is the kind of thing I am getting now:

Installation Notes:
1. This is the command for the first step.
2. This is the command for the second step.
3. This is the command for the third step.This is the first para in
step three.This is the second para in step three.This is the first
note in step three.This is the second note in step three.This is the
third note in step three.This is the third para in step three.This is
the fourth para in step three.
4. This is the command for the final step.This is the only note in step four.

This is what I want:

Installation Notes:
1. This is the command for the first step.
2. This is the command for the second step.
3. This is the command for the third step.
This is the first para in step three.
This is the second para in step three.
This is the first note in step three.
This is the second note in step three.
This is the third note in step three.
This is the third para in step three.
This is the fourth para in step three.
4. This is the command for the final step.
This is the only note in step four.

How do I render my XML source the way I want it? I have included my
XML source and XSL sheet below. Can someone set me straight?

Here's my XML source:
<?xml version="1.0" encoding="UTF-8"?>
<install>
	<step>
		<command>This is the command for the first step.</command>
	</step>
	<step>
		<command>This is the command for the second step.</command>
	</step>
	<step>
		<command>This is the command for the third step.</command>
		<para>This is the first para in step three.</para>
		<para>This is the second para in step three.</para>
		<note>This is the first note in step three.</note>
		<note>This is the second note in step three.</note>
		<note>This is the third note in step three.</note>
		<para>This is the third para in step three.</para>
		<para>This is the fourth para in step three.</para>
	</step>
	<step>
		<command>This is the command for the final step.</command>
		<note>This is the only note in step four.</note>
	</step>
</install>

Here's my dysfunctional XSL:
<?startSampleFile?>
<!DOCTYPE stylesheet [
	<!ENTITY space "<xsl:text> </xsl:text>">
	<!ENTITY cr "<xsl:text>
</xsl:text>">
]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format";>
	<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>

<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="command para note"/>

  <xsl:variable name="newline">
<xsl:text>
</xsl:text>
  </xsl:variable>

	<xsl:template match="install">
<xsl:text>Installation Notes:</xsl:text>&cr;
		<xsl:for-each select="step">
			<xsl:sort select="step"/>
				<xsl:number value="position()" format="1. "/>
					<xsl:choose>
						<xsl:when test="command">
							<xsl:value-of select="."/>
							<xsl:value-of select="$newline"/>
						</xsl:when>
						<xsl:when test="note">
							<xsl:apply-templates select="note"/>
							<xsl:value-of select="$newline"/>
						</xsl:when>
						<xsl:when test="para">
							<xsl:apply-templates select="para"/>
							<xsl:value-of select="$newline"/>
						</xsl:when>
					</xsl:choose>
			</xsl:for-each>

</xsl:template>



	<?endSampleFile?>
</xsl:stylesheet>


I have also tried using this bit of code to get the contents of each
step node, but I think it is pretty ham-fisted.
<xsl:for-each select="step">
				<xsl:sort select="step"/>
				<xsl:number value="position()" format="1. "/>
			<xsl:apply-templates select="node()"/>
	</xsl:for-each>

Thanks in advance,
Andy Hall

Current Thread