Hi, Andy,
I don't fiddle with text output much (I mostly work on the opposite end of
the spectrum: XSL:FO), but I was able to get a decent text output of your
sample. It has more line breaks than your desired result, but white space
is good, right? :D
Here's the XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes"/>
<xsl:template match="install">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="step">
<xsl:text>
</xsl:text>
<xsl:number format="1. "/><xsl:value-of select="command"/><xsl:text>
</xsl:text><xsl:apply-templates select="para|note"/>
</xsl:template>
<xsl:template match="command"/>
<xsl:template match="para">
<xsl:text>
</xsl:text><xsl:value-of select="."/>
<xsl:if test="position() = last()"><xsl:text>
</xsl:text></xsl:if>
</xsl:template>
<xsl:template match="note">
<xsl:text>
</xsl:text>Note: <xsl:value-of select="."/>
<xsl:if test="position() = last()"><xsl:text>
</xsl:text></xsl:if>
</xsl:template>
</xsl:stylesheet>
And the result:
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.
Note: This is the first note in step three.
Note: This is the second note in step three.
Note: 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.
Note: This is the only note in step four.
Maybe you can find a happy medium between yours and mine and get what you
want.
Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)
Andy <achall(_at_)gmail(_dot_)com>
05/26/2005 02:47 PM
Please respond to
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
cc
Subject
[xsl] more nesting node questions
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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--