[xsl] Errors with JAXP

Subject: [xsl] Errors with JAXP
From: <igutierrez027@xxxxxxxxxxxxx>
Date: Wed, 5 Mar 2008 13:53:42 +0100 (CET)
Hello everybody!

I am using JAXP to execute XSLT 2.0. To implement the templates I am
using Oxygen. The templates doing well in Oxygen but with JAXP occurs
some errors.
I need to insert one element in one XSD after the element 'reviewed'.
The output will be the same XSD with the element inserted on it. This
is my XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified" version="2.0"
  targetNamespace="http://bibtexml.sf.net/";
xmlns:dc="http://purl.org/dc/elements/1.1/";
  xmlns:ns1="http://bibtexml.sf.net/";>

  <xs:import namespace="http://purl.org/dc/elements/1.1/";
schemaLocation="dc.xsd"/>
..
  <xs:element name="dateofread" type="xs:date"/>
  <xs:element name="reviewed" type="xs:string"/>
</xs:schema>

In the stylesheet that I am using I have two options of template to
insert the element. This is the XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:ns1="http://bibtexml.sf.net/";
    xmlns:dc="http://purl.org/dc/elements/1.1/";>

    <xsl:output method="xml"/>

    <xsl:param name="file" as="xs:string"/>
    <xsl:param name="type2" as=" xs:string"/>

    <xsl:attribute-set name="ns1:definicion">
        <xsl:attribute name="name">
            <xsl:value-of select="$file"/>
        </xsl:attribute>
        <xsl:attribute name="type" select=" concat('xs:',$type2)"/>
    </xsl:attribute-set>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>

FIRST OPTION:

    <xsl:template match="xs:element[@name='reviewed']">
        <xsl:next-match/>
        <xsl:element name="xs:element"
         use-attribute-sets="ns1:definicion"/>
    </xsl:template>

SECOND OPTION:

    <xsl:template match="xs:schema">
        <xsl:copy>
            <xsl:variable name="x"
                 select="xs:element[@name='reviewed']"/>
            <xsl:apply-templates select="$x/preceding-sibling::node()"/>
            <xsl:element name="xs:element"
                   use-attribute-sets="ns1:definicion"/>
            <xsl:apply-templates select="$x/(.,following-sibling::node
())"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

For execute with JAXP I use the next program:

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.lang.String;

public class prog1 {
	public static void main(String[] args) {
		Transformer transformer;
		TransformerFactory factory =
TransformerFactory.newInstance();
		String stylesheet
= "file:///C:/Users/Izaskun/workspace2/my_stylesheet.xsl";
		String sourceId
= "file:///C:/Users/Izaskun/workspace2/my_xsd.xsd";
		try {
		transformer = factory.newTransformer(new StreamSource
(stylesheet));
		transformer.setParameter("file", "campoNuevo");
		transformer.setParameter("type2", "string");
           	transformer.transform(new StreamSource(sourceId), new
StreamResult(System.out));
		} catch (Exception e) {
		    // handle error
		}
	}
}

And they are the errors:

For the FIRST OPTION of template:

ERROR:  'Unsupported XSL
element 'http://www.w3.org/1999/XSL/Transform:next-match''

For the SECOND OPTION of template:

ERROR:  'Error of sintaxis in '$x/(.,following-sibling::node())'.'

Could anybody help me?

Thank You.

Regards,

Izaskun Gutierrez

Current Thread