Thanks Michael, however I am forced to use the JAXP implementation (project
constraint). Do you know of any other way around the issue?
Kind regards
Stephen
-----Original Message-----
From: Michael Dykman [mailto:mdykman(_at_)gmail(_dot_)com]
Sent: 26 August 2010 17:11
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Namespace issue when running a Xalan transform through Java
When you say Java and Xalan, do you mean you are using the
internalized version of Xalan that was hacked into the core libraries
to proide a default for JAXP or are you using the standalone Xalan
package and overriding the default implementation?
The internalized version Sun saw fit to hack in is notoriously buggy.
If you bootstrap an external xslt transformer such as standalone Xalan
or Saxon, you will find that Java does XSLT very well indeed,
If you download the newest saxon and just put it in your class path,
it will assert itself as the default transformer and I would not be
surprised at all if your code just works after that.
- michael dykman
On Thu, Aug 26, 2010 at 11:52 AM, Etheridge, Stephen
<stephen(_dot_)etheridge(_at_)logica(_dot_)com> wrote:
Hi List
Apologies for a newbie question:
I have an XSLT that runs perfectly well through XSLTProc and Xalan
(through the Oxygen editor) so it would seem that my XSLT works.
However, when I run the XSLT on the same input XML file through Java
calling Xalan, I get multiple elements each having a namespace of the
format:
<ElementName xmlns:nsX=http://www.logica.com/project> where X increments
from 0 to 4295 in my particular case!
The Java I am using is the standard one which I cribbed from the Net:
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
public class BasicXsl {
// This method applies the xslFilename to inFilename and writes
// the output to outFilename.
public static void main() {
String inFileName = "filename";
String outFileName = "filename";
String xslFileName = "filename";
try {
TransformerFactory factory =
TransformerFactory.newInstance();
Templates template = factory.newTemplates(new
StreamSource(new FileInputStream(xslFilename)));
Transformer xformer = template.newTransformer();
Source source = new StreamSource(new
FileInputStream(inFilename));
Result result = new StreamResult(new
FileOutputStream(outFilename));
xformer.transform(source, result);
} catch (FileNotFoundException e) {
} catch (TransformerConfigurationException e) {
// An error occurred in the XSL file
} catch (TransformerException e) {
// An error occurred while applying the XSL file
// Get location of error in input file
SourceLocator locator = e.getLocator();
int col = locator.getColumnNumber();
int line = locator.getLineNumber();
String publicId = locator.getPublicId();
String systemId = locator.getSystemId();
}
}
}
Does anyone have any idea why I am getting the extraneous namespaces on
the transformed elements (it is not all elements but the children of
/Root/Child/ - i.e. those lower in the tree), or how to get rid of them?
Thanks in advance
Stephen Etheridge
Please help Logica to respect the environment by not printing this email /
Pour contribuer comme Logica au respect de l'environnement, merci de ne pas
imprimer ce mail / Bitte drucken Sie diese Nachricht nicht aus und helfen
Sie so Logica dabei, die Umwelt zu schützen. / Por favor ajude a Logica a
respeitar o ambiente nao imprimindo este correio electronico.
This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be copied,
disclosed to, retained or used by, any other party. If you are not an
intended recipient then please promptly delete this e-mail and any attachment
and all copies and inform the sender. Thank you.
--~------------------------------------------------------------------
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>
--~--
--
- michael dykman
- mdykman(_at_)gmail(_dot_)com
May the Source be with you.
--~------------------------------------------------------------------
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>
--~--
Please help Logica to respect the environment by not printing this email /
Pour contribuer comme Logica au respect de l'environnement, merci de ne pas
imprimer ce mail / Bitte drucken Sie diese Nachricht nicht aus und helfen Sie
so Logica dabei, die Umwelt zu schützen. / Por favor ajude a Logica a
respeitar o ambiente nao imprimindo este correio electronico.
This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be copied,
disclosed to, retained or used by, any other party. If you are not an intended
recipient then please promptly delete this e-mail and any attachment and all
copies and inform the sender. Thank you.
--~------------------------------------------------------------------
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>
--~--