xsl-list
[Top] [All Lists]

RE: [xsl] Errors with JAXP

2008-03-05 06:05:17
Both are failing because you are using XSLT 2.0 syntax, and you must be
picking up an XSLT 1.0 processor.

Since there's only one XSLT 2.0 processor that supports JAXP, you can't
really make your code portable, so the simplest solution is to bypass the
JAXP factory mechanism (which in any case is very slow), and replace:

TransformerFactory factory = TransformerFactory.newInstance();

with

TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();

Alternatively, this particular transformation could very easily be written
using XSLT 1.0 syntax alone.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: igutierrez027(_at_)ikasle(_dot_)ehu(_dot_)es 
[mailto:igutierrez027(_at_)ikasle(_dot_)ehu(_dot_)es] 
Sent: 05 March 2008 12:54
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Errors with JAXP

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[(_at_)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[(_at_)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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>