4

I have a XSLT which will split large xml file into multiple xml file with the use of following xslt code.

<xsl:variable name="filename" select="resolve-uri(concat('splitfilesfolder/',position(),'.xml'))" /> 
 <xsl:result-document href="{$filename}" format="xml">
    <--XML file content --->
 </xsl:result-document>

then i have used that XSLT in my code to split input XML file using javax.xml.transform.Transformer.

TransformerFactory tFactory = TransformerFactory.newInstance();
Source xslSource =  new StreamSource(xsltfilepath);

Transformer trans = tFactory.newTransformer(xslSource);
trans.transform(new StreamSource(xmlFileName), new StreamResult(splitfilesfolder));

Here i want to give same path for new Streamresult as it is in result document path how can i transform multiple xml file using result doucment and javax.xml.transform.Transform ??

Can anybody please give me a solution ?

Thanks in advance.

2 Answers 2

3

<xsl:result-document> is in XSLT 2.0 javax.xml.transform does not support XSLT 2.0, so i'm under the impression that you're out of luck using built-in transformers.

Try using Saxon instead. Just add the jar file to your classpath and you're set.

There is also an error in your XSLT

 <xsl:result-document href="{$filename}" format="xml">

Should be

 <xsl:result-document href="{$filename}" method="xml">

To get the directory into your XSLT i'd use

Java

trans.setParameter("dir", "dirname");

XSL

<xsl:param name="dir"/>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Peter , I have resolved my problem what you have suggested. I have used Saxon for the result document and split the file .
0

Create an instance of Saxon's TransformerFactory directly, i.e. TransformerFactoryImpl factory = new TransformerFactoryImpl(); Do not use the brain-dead JAXP TransformerFactory.newInstance(); ...as you're clearly getting something other than Saxon's implmentation.

1 Comment

Since Java 1.6, you can make sure you get the implementation you want using TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl", null), for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.