At 2003-09-06 21:02 +0200, Iván Montoro Ten wrote:
I'm building several manuals with XML for a product we make. I've
seen several frameworks for it, but I'm looking for something
easier, as a bare XML file and a XSL HTML transform (maybe later
I'll get PDF, but that's too much for me right now!)
It might seem scary, but it is as easy as for HTML, just with a different
output vocabulary. There are two free book excerpts you can download from
our web site to learn more and to use as reference material. As well, we
are running two publicly-subscribed training courses in Europe in two
week's time that will cover *every* element, attribute and function in XSLT
and *every* formatting object in XSL-FO.
I've the basic skeleton for my document. I want XSL to transform
this in a basic <P></P>, <H1></H1>, <H2></H2> structure, but
I don't know how to iterate the subelements linearly, rather I
know how to xsl:for-each them. Is there any solution for this?
<xsl:for-each> is a "pull" approach to the information.
<xsl:apply-templates/> is a "push" approach to the information. The free
excerpts give a characterization of these two approaches and contrasts some
example stylesheets in each approach.
See a complete example using your data below that illustrates this push
approach.
I hope this helps.
............... Ken
p.s. I'm curious why you modelled your titles as attributes ... I would
recommend that language-oriented content be in #PCDATA and machine-oriented
content be in attributes ... this will allow you to add structure
(emphasis, font style, etc) to portions of your titles ... if you leave
your titles as attributes, which cannot be structured, you will be limited
in the future as your data matures.
T:\ftemp>type ivan.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<manual>
<chapter title="Begining with...">
<sub1 title="To start...">
<para>text text text</para>
<sub2 title="What you need">
<para>text text text</para>
</sub2>
<sub2 title="Doing it well">
<para>text text text</para>
<sub3 title="Don't forget...">
<para>text text text</para>
</sub3>
<para>text text text</para>
</sub2>
</sub1>
</chapter>
</manual>
T:\ftemp>type ivan.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html><xsl:apply-templates/></html>
</xsl:template>
<xsl:template match="sub1">
<h1><xsl:value-of select="@title"/></h1>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="sub2">
<h2><xsl:value-of select="@title"/></h2>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="sub3">
<h3><xsl:value-of select="@title"/></h3>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="para">
<p><xsl:apply-templates/></p>
</xsl:template>
</xsl:stylesheet>
T:\ftemp>saxon ivan.xml ivan.xsl
<html>
<h1>To start...</h1>
<p>text text text</p>
<h2>What you need</h2>
<p>text text text</p>
<h2>Doing it well</h2>
<p>text text text</p>
<h3>Don't forget...</h3>
<p>text text text</p>
<p>text text text</p>
</html>
T:\ftemp>
--
Next public European delivery: 3-day XSLT/2-day XSL-FO 2003-09-22
Next public US delivery: 3-day XSLT/2-day XSL-FO 2003-10-13
Instructor-led on-site corporate, government & user group training
for XSLT and XSL-FO world-wide: please contact us for the details
G. Ken Holman mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6 Definitive XSLT and XPath
ISBN 0-13-140374-5 Definitive XSL-FO
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-11-X Practical Formatting Using XSL-FO
Member of the XML Guild of Practitioners: http://XMLGuild.info
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list