error compile stylesheet

hi!

i need to transform a xml file into html file using docbook styleseheets, my java is:

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.Transformer;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.*;

import java.io.File;

import org.w3c.dom.Document;

publicclass xmlTransformer

{

publicstaticvoid main(String[] args)

{

File sourceFileName =new File("result.xml");//book chapter

File stylesheet =new File("html.xsl");//this is docbook stylesheet

File transformFileName =new File("result.html");

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setNamespaceAware(true);

try{

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.parse(sourceFileName);

StreamSource stylesource =new StreamSource(stylesheet);

TransformerFactory xfFactory = TransformerFactory.newInstance();

Transformer transformer = xfFactory.newTransformer(stylesource);

DOMSource source =new DOMSource(document);

StreamResult result =new StreamResult(transformFileName);

transformer.transform(source,result);

}

catch(Exception e){

e.printStackTrace();

System.out.println("Error transforming XML - " + e.getMessage());

}

}

}

and i get this error:

ERROR: 'file:/D:/Work/workspace-3.2/transform/html.xsl: line 55: Template 'object.id' not defined in this stylesheet.'

FATAL ERROR: 'Could not compile stylesheet'

javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet

at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:824)

at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:613)

at xmlTransformer.main(xmlTransformer.java:29)

Error transforming XML - Could not compile stylesheet

can anyone help me please?

[3307 byte] By [Taigoa] at [2007-11-27 9:15:11]
# 1

Your XSL stylesheet contains a reference to a template name ("object.id") that matches none of the names of the defined templates.

Example

This stylesheet has an error because the template named "undefined_template" is referred to but not defined:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:call-template name="undefined_template"/>

</xsl:stylesheet>

If you attempt to use this stylesheet for an XSL transformation, the following error will be encountered:ERROR:...: Template 'undefined_template' not defined in this stylesheet.'

FATAL ERROR: 'Could not compile stylesheet'

javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet

at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:824)

at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:613)

...By contrast, this stylesheet works fine because the template named "defined_template" is defined:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:call-template name="defined_template"/>

<xsl:template name="defined_template"/>

</xsl:stylesheet>

prgguya at 2007-7-12 22:04:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

hi prgguy! thank you once again!

but.. i don't understand very well want i have to do to put may html.xsl working.

i 'm using a docbook xsl, and its like :

<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

version='1.0'>

<!-- ********************************************************************

$Id$

********************************************************************

This file is part of the XSL DocBook Stylesheet distribution.

See ../README or http://nwalsh.com/docbook/xsl/ for copyright

and other information.

******************************************************************** -->

<!-- The generate.html.title template is currently used for generating HTML -->

<!-- "title" attributes for some inline elements only, but not for any -->

<!-- block elements. It is called in eleven places in the inline.xsl -->

<!-- file. But it's called by all the inline.* templates (e.g., -->

<!-- inline.boldseq), which in turn are called by other (element) -->

<!-- templates, so it results, currently, in supporting generation of the -->

<!-- HTML "title" attribute for a total of about 92 elements. -->

<xsl:template name="generate.html.title">

<xsl:if test="alt">

<xsl:attribute name="title">

<xsl:value-of select="normalize-space(alt)"/>

</xsl:attribute>

</xsl:if>

</xsl:template>

<xsl:template name="dir">

<xsl:param name="inherit" select="0"/>

<xsl:variable name="dir">

<xsl:choose>

<xsl:when test="@dir">

<xsl:value-of select="@dir"/>

</xsl:when>

<xsl:when test="$inherit != 0">

<xsl:value-of select="ancestor::*/@dir[1]"/>

</xsl:when>

</xsl:choose>

</xsl:variable>

<xsl:if test="$dir != ''">

<xsl:attribute name="dir">

<xsl:value-of select="$dir"/>

</xsl:attribute>

</xsl:if>

</xsl:template>

<xsl:template name="anchor">

<xsl:param name="node" select="."/>

<xsl:param name="conditional" select="1"/>

<xsl:variable name="id">

<xsl:call-template name="object.id">

<xsl:with-param name="object" select="$node"/>

</xsl:call-template>

</xsl:variable>

<xsl:if test="$conditional = 0 or $node/@id or $node/@xml:id">

<a name="{$id}"/>

</xsl:if>

</xsl:template>

<xsl:template name="href.target.uri">

<xsl:param name="context" select="."/>

<xsl:param name="object" select="."/>

<xsl:text>#</xsl:text>

<xsl:call-template name="object.id">

<xsl:with-param name="object" select="$object"/>

</xsl:call-template>

</xsl:template>

<xsl:template name="href.target">

<xsl:param name="context" select="."/>

<xsl:param name="object" select="."/>

<xsl:text>#</xsl:text>

<xsl:call-template name="object.id">

<xsl:with-param name="object" select="$object"/>

</xsl:call-template>

</xsl:template>

<xsl:template name="href.target.with.base.dir">

<xsl:param name="context" select="."/>

<xsl:param name="object" select="."/>

<xsl:if test="$manifest.in.base.dir = 0">

<xsl:value-of select="$base.dir"/>

</xsl:if>

<xsl:call-template name="href.target">

<xsl:with-param name="context" select="$context"/>

<xsl:with-param name="object" select="$object"/>

</xsl:call-template>

</xsl:template>

<xsl:template name="dingbat">

<xsl:param name="dingbat">bullet</xsl:param>

<xsl:call-template name="dingbat.characters">

<xsl:with-param name="dingbat" select="$dingbat"/>

</xsl:call-template>

</xsl:template>

<xsl:template name="dingbat.characters">

<!-- now that I'm using the real serializer, all that dingbat malarky -->

<!-- isn't necessary anymore... -->

<xsl:param name="dingbat">bullet</xsl:param>

<xsl:choose>

<xsl:when test="$dingbat='bullet'">?lt;/xsl:when>

<xsl:when test="$dingbat='copyright'">?lt;/xsl:when>

<xsl:when test="$dingbat='trademark'">?lt;/xsl:when>

<xsl:when test="$dingbat='trade'">?lt;/xsl:when>

<xsl:when test="$dingbat='registered'">?lt;/xsl:when>

<xsl:when test="$dingbat='service'">(SM)</xsl:when>

<xsl:when test="$dingbat='nbsp'"> </xsl:when>

<xsl:when test="$dingbat='ldquo'">?lt;/xsl:when>

<xsl:when test="$dingbat='rdquo'">?lt;/xsl:when>

<xsl:when test="$dingbat='lsquo'">?lt;/xsl:when>

<xsl:when test="$dingbat='rsquo'">?lt;/xsl:when>

<xsl:when test="$dingbat='em-dash'">?lt;/xsl:when>

<xsl:when test="$dingbat='mdash'">?lt;/xsl:when>

<xsl:when test="$dingbat='en-dash'">?lt;/xsl:when>

<xsl:when test="$dingbat='ndash'">?lt;/xsl:when>

<xsl:otherwise>

<xsl:text>?lt;/xsl:text>

</xsl:otherwise>

</xsl:choose>

</xsl:template>

<xsl:template name="id.warning">

<xsl:if test="$id.warnings != 0 and not(@id) and not(@xml:id) and parent::*">

<xsl:variable name="title">

<xsl:choose>

<xsl:when test="title">

<xsl:value-of select="title[1]"/>

</xsl:when>

<xsl:when test="substring(local-name(*[1]),

string-length(local-name(*[1])-3) = 'info')

and *[1]/title">

<xsl:value-of select="*[1]/title[1]"/>

</xsl:when>

<xsl:when test="refmeta/refentrytitle">

<xsl:value-of select="refmeta/refentrytitle"/>

</xsl:when>

<xsl:when test="refnamediv/refname">

<xsl:value-of select="refnamediv/refname[1]"/>

</xsl:when>

</xsl:choose>

</xsl:variable>

<xsl:message>

<xsl:text>ID recommended on </xsl:text>

<xsl:value-of select="local-name(.)"/>

<xsl:if test="$title != ''">

<xsl:text>: </xsl:text>

<xsl:choose>

<xsl:when test="string-length($title) > 40">

<xsl:value-of select="substring($title,1,40)"/>

<xsl:text>...</xsl:text>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="$title"/>

</xsl:otherwise>

</xsl:choose>

</xsl:if>

</xsl:message>

</xsl:if>

</xsl:template>

</xsl:stylesheet>

i don,t know exactly what a i have to do :(

can you help me again? please.

Taigoa at 2007-7-12 22:04:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

This stylesheet contains the following errors:

1. The definition of the template "object.id" is missing from the stylesheet.

2. The definition of the variable "manifest.in.base.dir" is missing from template "href.target.with.base.dir".

3. The definition of the variable "base.dir" is missing from template "href.target.with.base.dir".

4. The definition of the variable "id.warnings" is missing from template "id.warning".

If you include these definitions in your stylesheet, the XSL transformation will work, whatever this stylesheet is supposed to produce.

prgguya at 2007-7-12 22:04:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
hi!but i don't know how to include these definitions :( can you tell me how?
Taigoa at 2007-7-12 22:04:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

The following site says that the undefined variables I mentioned in my last post are really "user-configurable parameters" (which may also be declared as variables) in the DocBook XSL HTML stylesheets for generating HTML output.

http://docbook.sourceforge.net/release/xsl/current/doc/html

It means that you can't use this stylesheet out of the box because you have to define these parameters/variables for the stylesheet to work. That being so it's up to you to define them; I can only tell you where to place them in general.

A possible (though not necessarily the ideal) solution may be to insert the missing template and parameters/variables as child nodes into the <xsl:stylesheet> element:<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>

...

<xsl:template name="object.id"/>

<xsl:param name="manifest.in.base.dir" select="expression"/>

<xsl:param name="base.dir" select="expression"/>

<xsl:param name="id.warnings" select="expression"/>

</xsl:stylesheet>

or:<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>

...

<xsl:template name="object.id"/>

<xsl:variable name="manifest.in.base.dir" select="expression"/>

<xsl:variable name="base.dir" select="expression"/>

<xsl:variable name="id.warnings" select="expression"/>

</xsl:stylesheet>

Note that these examples are for demonstration purposes only. You will need to fill the inserted elements with appropriate content as well as replace the value of the "select" attributes with some other values of your own.

prgguya at 2007-7-12 22:04:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...