Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3695930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:40:38+00:00 2026-05-19T04:40:38+00:00

I am using xalan 2.7.1 to validate my xml docs with xslt style sheet.

  • 0

I am using xalan 2.7.1 to validate my xml docs with xslt style sheet. It works fine for the first document and returns error message in case of error along with correct line and column number of xml source by making use of NodeInfo.lineNumber and NodeInfo.columnNumber extensions.

The problem is when I try to reuse transformer to validate other xml docs, it successfully transforms the document but always returns lineNumber=columnNumber=-1 for all errors.
Any idea?

Edit: Here is my code::

package mycompany;

import java.io.File;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.xalan.processor.TransformerFactoryImpl;

public class XsltTransformer {

    public static void main(String[] args) {

        TransformerFactory tFactory = TransformerFactory.newInstance();
        tFactory.setAttribute(TransformerFactoryImpl.FEATURE_SOURCE_LOCATION, Boolean.TRUE);

        StreamSource xsltStreamSource = new StreamSource(new File("E:\\Temp\\Test\\myXslt.xsl"));
        try {
            Transformer transformer = tFactory.newTransformer(xsltStreamSource);

            File srcFolder = new File("E:\\Temp\\Test");
            for (File file : srcFolder.listFiles()) {
                if (file.getName().endsWith("xml")) {

                    Source source = new StreamSource(file);
                    StreamResult result = new StreamResult(System.out);

                    XsltTransformer xsltTransformer = new XsltTransformer();
                    ErrorListenerImpl errorHandler = xsltTransformer.new ErrorListenerImpl();
                    transformer.setErrorListener(errorHandler);

                    transformer.transform(source, result);

                    if (errorHandler.e != null) {
                        System.out.println("Transformation Exception: " + errorHandler.e.getMessage());
                    }

                    transformer.reset();
                }
            }

        } catch (TransformerException e) {
            e.printStackTrace();
        }
    }

    private class ErrorListenerImpl implements ErrorListener {
        public TransformerException e = null;

        public void error(TransformerException exception) {
            this.e = exception;
        }

        public void fatalError(TransformerException exception) {
            this.e = exception;
        }

        public void warning(TransformerException exception) {
            this.e = exception;
        }
    }
}

Edit: Here are myXslt.xsl and XML sources:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<axsl:stylesheet 
    xmlns:axsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:iso="http://purl.oclc.org/dsdl/schematron" 
    xmlns:sch="http://www.ascc.net/xml/schematron"
    version="1.0" 
    xmlns:nodeinfo="xalan://org.apache.xalan.lib.NodeInfo">

  <axsl:output 
      xmlns:svrl="http://purl.oclc.org/dsdl/svrl" 
      xmlns:schold="http://www.ascc.net/xml/schematron" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      indent="yes" 
      standalone="yes" 
      omit-xml-declaration="no" 
      method="xml" />

  <!--SCHEMA METADATA -->
  <axsl:template match="/">
    <svrl:schematron-output xmlns:svrl="http://purl.oclc.org/dsdl/svrl" xmlns:schold="http://www.ascc.net/xml/schematron" 
                            xmlns:xs="http://www.w3.org/2001/XMLSchema" schemaVersion="ISO19757-3" title="Test ISO schematron file. Introduction mode ">
      <svrl:active-pattern>
        <axsl:apply-templates />
      </svrl:active-pattern>
      <axsl:apply-templates mode="M1" select="/" />
    </svrl:schematron-output>
  </axsl:template>

  <!--RULE -->
  <axsl:template mode="M1" priority="1000" match="//*[@remote-property]">
    <svrl:fired-rule xmlns:svrl="http://purl.oclc.org/dsdl/svrl" xmlns:schold="http://www.ascc.net/xml/schematron" 
                     xmlns:xs="http://www.w3.org/2001/XMLSchema" context="//*[@remote-property]" />

    <!--ASSERT -->
    <axsl:choose>
      <axsl:when test="@remote-property = //@id or @remote-property = //@name" />
      <axsl:otherwise>
        <svrl:failed-assert xmlns:svrl="http://purl.oclc.org/dsdl/svrl" xmlns:schold="http://www.ascc.net/xml/schematron" 
                            xmlns:xs="http://www.w3.org/2001/XMLSchema" test="@remote-property = //@id or @remote-property = //@name">
          <axsl:attribute name="lineNumber">
              <axsl:value-of select="nodeinfo:lineNumber()" />
          </axsl:attribute>
          <axsl:attribute name="columnNumber">
              <axsl:value-of select="nodeinfo:columnNumber()" />
          </axsl:attribute>
          <svrl:text>
            Invalid remote-property: remote class element with this id or name does not exists
      </svrl:text>
        </svrl:failed-assert>
      </axsl:otherwise>
    </axsl:choose>
  </axsl:template>
</axsl:stylesheet>

source1.xml:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <remote-service>
        <class name="Table1" table="table1">
            <id name="col1"/>
            <property name="col2"/>
        </class>
    </remote-service>
    <application>
        <text-field name="field1" remote-property="col1X"/>
    </application>
</root> 

and source2.xml

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <application>
        <text-field name="field1" remote-property="col1Z"/>
    </application>
</root> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:40:39+00:00Added an answer on May 19, 2026 at 4:40 am

    The javadoc states:

    The reset Transformer is not
    guaranteed to have the same
    URIResolver or ErrorListener Objects

    You might have to reset your ErrorListener reference to the new ErrorListener of the reset transformer.

    update

    I have no experience with the schematron library, from what I see it is probably an issue of that library being used by a reset transformer.

    If you cannot get it to work resetting the transformer you might be able to use the XSL template facility to prevent having to interpret the XSL sheet on every transorm:

    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.Templates;
    import javax.xml.transform.Transformer;
    
    TransformerFactory factory = TransformerFactory.newInstance();
    
    Templates xslTemplate = factory.newTemplates(new StreamSource(new StringReader(xsl)));
    

    Later re-use the template by getting the transformer from it:

    Transformer transformer = xslTemplate.newTransformer();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to output a CDATA section in the result of XSLT using Xalan
Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
I am using Xalan and Java for extending a stylesheet. (Similar example to what
I have several different XSLT files that all work on the same original XML
I have to process XML files that have a DTD with a XSLT in
I'd like to add an element to a xml document and I'd like to
In a xslt-stylesheet I'm using the methods exsl:node-set and set:distinct to access and filter
Using the below XML, I need to figure out which person worked more hours
I am facing problems with using xalan in eclipse plugin. When I try to
Using online interfaces to a version control system is a nice way to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.