XSLT: change namespace in transformer, not insert into stylesheet / remove namespace prefix

I am transforming some XML using XSLT and Saxon like this:

    Source sourceXML = new StreamSource(...);
    Source sourceXSLT = new StreamSource(...);

    System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
    TransformerFactory transFact = TransformerFactory.newInstance();

    Templates cachedXSLT = transFact.newTemplates(sourceXSLT);

    Transformer transformer = cachedXSLT.newTransformer();
    transformer.setOutputProperty("indent", "no");

    transformer.transform(sourceXML, new StreamResult(System.out));

      

The stylesheet is created with MapForce and changes frequently. While the conversion works, it generally prefixes all elements with the n namespace. This is likely due to the following line in the stylesheet:

<xsl:namespace-alias stylesheet-prefix="n" result-prefix="#default"/>

      

Since the MapForce tool does not show this prefix in it, it is probably very easy to change it in the transformer. Can someone point me in the right direction? Or do I need to do some (manual) preprocessing on the stylesheet to get rid of it?

A stripped down version of the stylesheet looks like this:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:n="..." xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:grp="http://www.altova.com/Mapforce/grouping" exclude-result-prefixes="fn grp xs xsi xsl" xmlns="...">
    <xsl:namespace-alias stylesheet-prefix="n" result-prefix="#default"/>
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
    ...
    </xsl:template>
</xsl:stylesheet>

      

+2


source to share





All Articles