Altova Mailing List Archives

Re: [xsl] Building a Manual with XML/XSL

From: "G. Ken Holman" <gkholman@-------------------->
Date: 9/6/2003 12:02:00 PM
At 2003-09-06 21:02 +0200, Iv&aacute;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 

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"?>
  <chapter title="Begining with...">
    <sub1 title="To start...">
      <para>text text text</para>
      <sub2 title="What you need">
        <para>text text text</para>
      <sub2 title="Doing it well">
        <para>text text text</para>
        <sub3 title="Don't forget...">
          <para>text text text</para>
        <para>text text text</para>

T:\ftemp>type ivan.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl=""

<xsl:template match="/">

<xsl:template match="sub1">
  <h1><xsl:value-of select="@title"/></h1>

<xsl:template match="sub2">
  <h2><xsl:value-of select="@title"/></h2>

<xsl:template match="sub3">
  <h3><xsl:value-of select="@title"/></h3>

<xsl:template match="para">

T:\ftemp>saxon ivan.xml ivan.xsl

   <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>


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@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
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:
Male Breast Cancer Awareness

XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.