facing problem in XSLT transformation

Hi all,

I m new bie to XSLT n transformation. I have written a simple java program that uses the javax.xml.transform and javax.xml.parsers package to transform source file using a XSL file provided.

When I excuted the program providing XSLT file that worked fine and transformed the XML but when I modified the XSLT and using Xpath functions, I m getting following exception :

ERROR: 'Cannot find class 'xpath-functions'.'

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 transformXML.main(transformXML.java:33)

This is my XSLT file:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0"

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

xmlns:xs="http://www.w3.org/2001/XMLSchema"

xmlns:fn="http://www.w3.org/2005/xpath-functions"

xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">

<Listfaultinterfaceslot>

<xsl:variable name="current_date" select="fn:string(fn:current-date())"/>

<!-- Get the components of the current date -->

<xsl:variable name="day">

<xsl:value-of select="fn:substring($current_date,9,2)"/>

</xsl:variable>

<xsl:variable name="month">

<xsl:value-of select="fn:substring($current_date,6,2)"/>

</xsl:variable>

<xsl:variable name="year">

<xsl:value-of select="fn:substring($current_date,1,4)"/>

</xsl:variable>

<xsl:variable name="formatted_date">

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

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

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

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

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

</xsl:variable>

<!-- Finally output the slots-->

<AppointmentSlot>

<xsl:attribute name="AppointmentSlotNo">1</xsl:attribute>

<xsl:attribute name="ExternalAppointmentSlotStart">

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

<xsl:text> 08:00:00</xsl:text>

</xsl:attribute>

<xsl:attribute name="ExternalAppointmentSlotEnd">

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

<xsl:text> 13:00:00</xsl:text>

</xsl:attribute>

</AppointmentSlot>

<AppointmentSlot>

<xsl:attribute name="AppointmentSlotNo">2</xsl:attribute>

<xsl:attribute name="ExternalAppointmentSlotStart">

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

<xsl:text> 13:00:00</xsl:text>

</xsl:attribute>

<xsl:attribute name="ExternalAppointmentSlotEnd">

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

<xsl:text> 18:00:00</xsl:text>

</xsl:attribute>

</AppointmentSlot>

</Listfaultinterfaceslot>

</xsl:template>

</xsl:stylesheet>

Please look into this n let me know the reason.

Thanks alot

Omesh

[3508 byte] By [Omesha] at [2007-11-27 8:07:04]
# 1
Does the transformer support XSLT 2.0?Saxonica supports XSLT 2.0. http://www.saxonica.com/
dvohra09a at 2007-7-12 19:49:44 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

thanks for response buddy.

I am using the Java 5 SDK and package " javax.xml.transform" to get transformer. As per my undestanding, Java 5 Sdk has xalan transformer.

This is my code:

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;

public class transformXML

{

public static void main(String[] args)

{

System.out.println("Hello World!");

String inputFile = args[0];

String styleFile = args[1];

String outFile = args[2];

File sourceFileName = new File(inputFile);

File stylesheet = new File(styleFile);

File transformFileName = new File(outFile);

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

//transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

DOMSource source = new DOMSource(document);

StreamResult result = new StreamResult(transformFileName);

transformer.transform(source,result);

}

catch(Exception e) {

e.printStackTrace();

//throw new Exception("Error transforming XML - " + e.getMessage());

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

}

}

I m looking for whether Java provided xalan transformer supports XSLT 2.0 or not. If u found any solution please let me know.

many thanks,

Omesh

Omesha at 2007-7-12 19:49:44 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
> m looking for whether Java provided xalan transformer> supports XSLT 2.0 or not. If u found any solution> please let me know.No, it doesn't.
DrClapa at 2007-7-12 19:49:44 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

thanks DrClap :)

wat would be the solution as XSLT is version 2.0 and contains use of xpath functions. The program is compling properly but when trying to execute it showing the error as Can not compile stylesheet / FATAL Error can not found class xpath functions.

I couldn't found any solution in last 2 days. Plz help me.

thanks alot...

Omesh

Omesha at 2007-7-12 19:49:44 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
Hi all,Does anyone has the sample code for XSLT transfromation based on the SAXON processor or any other processor that supports the XSLT v2.0?Thanks Omesh
Omesha at 2007-7-12 19:49:44 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...