Element in template match ignored when transforming

Here should go questions about transforming XML with XSLT and FOP.
burbles
Posts: 37
Joined: Wed Dec 23, 2009 6:13 am

Element in template match ignored when transforming

Post by burbles » Sun Jul 11, 2010 9:46 am

I am a newbie to XSL and really stuck with a few things trying to debug a set of stylesheets in oXygen 11.2.
I want to FO transform a book imprint page and my first problem is that the transform isn’t recognising the element name in the template match syntax – I’ve also tried different combinations of xsl:if and xsl:choose as part of the template match code, and have tried using only the element name in the template match and then stating the attribute pattern in an xsl:choose statement, but this doesn’t work. But when I replace the ‘para’ with ‘*’ then the transformation picks up the attribute styles (or at least has done for other styles on another page of the book) specified in the fo:block (although that only applies styles based on attribute values – and I want to specify styles based on element names without attributes).
My second problem is that, in the latest iteration of my xml and xsl files, I am getting an error message as shown below, which states: “Attribute 'region-start' cannot occur at element 'fo:block'.” Now, I did have a region-start value as part of fo:block, but I took this out and replaced it with start-indent – yet I am still getting the ‘region-start’ error.
I’ve tried to follow the logic from the DocBook 5 stylesheets and a few XSL-FO books but I’m stumped. Thanks in advance.
-----
XML file for the imprint page:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<preface xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" condition="imprint">
<para condition="legalnotice">© Commonwealth of Australia 2009</para>
<para condition="legalnotice">All rights reserved. Except under the conditions described in the
<citetitle>Australian Copyright Act 1968</citetitle> and subsequent amendments, no part
of this publication may be reproduced, stored in a retrieval system or transmitted in any
form or by any means, electronic, mechanical, photocopying, recording, duplicating or
otherwise, without the prior permission of the copyright owner. Contact <emphasis
role="bold">CSIRO</emphasis> PUBLISHING for all permission requests.</para>
<para condition="imprint">National Library of Australia Cataloguing-in-Publication entry</para>
<para condition="cip">Australia's biodiversity and climate change/Will Steffen ... [et
al]<?lnbr?>9780643096059 (pbk.)<?lnbr?>Includes
index.<?lnbr?>Bibliography.<?lnbr?>Biodiversity&#x2013;climatic
factors&#x2013;Australia.<?lnbr?>Biodiversity conservation&#x2013;Australia.<?lnbr?>Climatic
changes&#x2013;Environmental aspects&#x2013;Australia.<?lnbr?>Steffen. William L.,
1947&#x2013;<?lnbr?>333.950994</para>
<para condition="imprint">Published by<?lnbr?><emphasis role="bold">CSIRO</emphasis>
PUBLISHING<?lnbr?>150 Oxford Street (PO Box 1139)<?lnbr?>Collingwood VIC
3066<?lnbr?>Australia</para>
<para condition="imprint">Telephone: +61 3 9662 7666<?lnbr?>Local call: <?indent?>1300 788 000
(Australia only)<?lnbr?>Fax: <?indent?>+61 3 9662 7555<?lnbr?>Email:
<?indent?><email>publishing.sales@csiro.au</email><?lnbr?>Web site:
<?indent?><uri>www.publish.csiro.au</uri></para>
<annotation condition="imprint">
<para>Front cover (clockwise, from top left): Snow gums, <emphasis>Eucalyptus pauciflora
niphophila</emphasis>, Kosciuszko National Park, NSW (DEWHA/Tim Bond); leaf beetles
on a snow gum leaf, Namadgi National Park, ACT (DEWHA/Dionne Bond); southern leaf-tailed
gecko, <emphasis>Phyllurus platyurus</emphasis>, Lane Cove National Park, NSW (DCC/Erika
Alacs); water-lilies, <emphasis>Nymphaea macrosperma</emphasis>, Mornington, WA
(DEWHA/Nick Rains); hummock grasslands, <emphasis>Triodia</emphasis> sp.,Gawler Ranges
National Park, SA (DEWHA/Tim Bond); red-eyed tree frog, <emphasis>Litoria
chloris</emphasis>, QLD (Wiki Commons/Muhammad Mahdi Karim); Gouldian finch,
<emphasis>Chloebia gouldiae</emphasis>, Wongalara NT (DEWHA/Steve Murphy).</para>
</annotation>
<annotation condition="imprint">
<para>Back cover (left to right): Coastal sub-tropical rainforest, Sea Acres Nature Reserve,
NSW (DEWHA/Tim Bond); scentless rosewood in Murramarang National Park, NSW (DEWHA/Tim
Bond); hummock grassland on Newhaven Sanctuary, NT (DEWHA/Nick Rains).</para>
</annotation>
<annotation condition="imprint">
<para>Set in 10/13 Adobe Minion and ICT Stone Sans<?lnbr?>Cover and text design by James
Kelly<?lnbr?>Typeset by Desktop Concepts Pty Ltd, Melbourne<?lnbr?>Printed in China by
1010 Printing International Ltd</para>
</annotation>
<annotation condition="imprint">
<para>The paper this book is printed on is certified by the Forest Stewardship Council (FSC)
© 1996 FSC A.C. The FSC promotes environmentally responsible, socially beneficial and
economically viable management of the world's forests.</para>
<para><emphasis role="bold">CSIRO</emphasis> PUBLISHING publishes and distributes
scientific, technical and health science books, magazines and journals from Australia to
a worldwide audience and conducts these activities autonomously from the research
activities of the Commonwealth Scientific and Industrial Research organisation
(CSIRO).<?lnbr?>The views expressed in this publication are those of the author(s) and
do not necessarily represent those of, and should not be attributed to, the publisher or
CSIRO, or the Australian Government, or the Minister for Climate Change and Water or the
Minister for the Environment, Heritage and the Arts.</para>
</annotation>
</preface>
XSL master stylesheet “docbookmasterfo.xsl”, which calls the stylesheet “imprinttest” that states styles for the imprint page:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="http://docbook.org/ns/docbook" xmlns:exsl="http://exslt.org/common"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:ng="http://docbook.org/docbook-ng"
xmlns:db="http://docbook.org/ns/docbook"
xmlns:xi="http://www.w3.org/2001/XInclude"
exclude-result-prefixes="db ng exsl d" version="1.0">

<!--The following XSL files should be kept together in the same directory for them to be
imported properly; the exception is for the 'docbook.xsl' file, which is
in the DocBook standard distribution.-->
<xsl:import
href="file:///c:/DocBook_xslns/docbook-xsl-ns-1.75.2/fo/docbook.xsl" />
<!-- change this directory to point to the location of your 'docbook.xsl'
stylesheet -->
<xsl:import href="imprinttest.xsl" />
<!-- <xsl:import href="textformats.xsl" /> -->
<xsl:import href="processinginstructions.xsl" />
<!-- <xsl:import href="pagesetup.xsl" />
<xsl:import href="tables.xsl" />
<xsl:import href="graphics.xsl" />
<xsl:import href="endmatter.xsl" />
<xsl:import href="lists.xsl" />
<xsl:import href="psmi.xsl" /> -->

</xsl:stylesheet>
Relevant parts of the called stylesheet “imprinttest.xsl”:

Code: Select all

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="http://docbook.org/ns/docbook" xmlns:exsl="http://exslt.org/common"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:ng="http://docbook.org/docbook-ng"
xmlns:db="http://docbook.org/ns/docbook"
xmlns:xi="http://www.w3.org/2001/XInclude"
exclude-result-prefixes="db ng exsl d" version="1.0">

<!--Imprint page (verso); use element 'info' with attribute condition="imprint"
to wrap all other elements on the imprint page-->
<xsl:template match="para[@condition='imprint']">
<fo:block
font-family="$body.fontset"
font-size="10pt">
<xsl:attribute name="hyphenate">false</xsl:attribute>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<!--legal and copyright notices; use element 'legalnotice' for the imprint page-->
<xsl:template match="para[@condition='legalnotice']">
<fo:block
space-before="0.8cm"
space-before.conditionality="retain">
<xsl:attribute name="hyphenate">false</xsl:attribute>
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<!--cataloguing-in-publication notice; use element 'releaseinfo' for the imprint page-->
<xsl:template match="para[@condition='cip']">
<fo:block
space-before="0.8cm"
space-before.conditionality="retain"
start-indent="0.8cm">
<xsl:apply-templates/>
</fo:block>
</xsl:template>

<!--other text on imprint page; use element 'annotation' with attribute condition="imprint"
for the imprint page-->
<xsl:template match="annotation[@condition='imprint']">
<fo:block
space-before="0.8cm"
space-before.conditionality="retain">
<xsl:apply-templates/>
</fo:block>
</xsl:template>

</xsl:stylesheet>
Error message generated when I transform using RenderX XEP 4.17:
(document [system-id file:/C:/XML_datafiles/imprintpage2.xml]
(validate
[error] Attribute 'region-start' cannot occur at element 'fo:block'.
[error] Attribute 'region-start' cannot occur at element 'fo:block'.
[error] Attribute 'region-start' cannot occur at element 'fo:block'.
[error] Attribute 'region-start' cannot occur at element 'fo:block'.
[validation total: 4 errors]
[error] com.renderx.xep.lib.FormatterException: Invalid XSL FO source 'file:/C:/XML_datafiles/imprintpage2.xml': 4 errors found during validation
[error] javax.xml.transform.TransformerException: com.renderx.xep.lib.FormatterException: Invalid XSL FO source 'file:/C:/XML_datafiles/imprintpage2.xml': 4 errors found during validation
[error] formatting failed
[error] javax.xml.transform.TransformerException: com.renderx.xep.lib.FormatterException: Invalid XSL FO source 'file:/C:/XML_datafiles/imprintpage2.xml': 4 errors found during validation
Formatting failed.

adrian
Posts: 2580
Joined: Tue May 17, 2005 4:01 pm

Re: Element in template match ignored when transforming

Post by adrian » Mon Jul 12, 2010 3:09 pm

Hello

I couldn't reproduce this with the code snippets you have provided.

I see there's an import to another stylesheet that was omitted:
<xsl:import href="processinginstructions.xsl" />

Maybe it happens because some of the FO code generated by that stylesheet?

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Post Reply