tags:

views:

401

answers:

2

hi all,

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  A: 

<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"/>
Peter Lindqvist
Thanks Peter , I have resolved my problem what you have suggested.I have used Saxon for the result document and split the file .
Nisarg Mehta
Then I kindly ask of you to mark my answer as "accepted"
Peter Lindqvist
A: 

I have declared my directory path.

String  myFolderName = "c:/myfolder";

and then i have set parameter like this

trans.setParameter("dir", myFolderName);
trans.transform(new StreamSource(xmlFileName), new StreamResult(myFolderName));

and in my xslt i have declared like this ..

<xsl:param name="dir"/>  
<xsl:variable name="filename" select="resolve-uri(concat($dir,'/',position(),'.xml'))" />

when i perform

trans.transform(new StreamSource(xmlFileName), new StreamResult(myFolderName));

i got exception

 java.lang.NoClassDefFoundError: oracle/i18n/text/OraCollator
    at oracle.xml.xqxp.functions.builtIns.FNUtil.getColla tor(FNUtil.java:329)
    at oracle.xml.xqxp.datamodel.OXMLItem.compareValue(OX MLItem.java:898)
    at oracle.xml.xpath.XPathItem.compareValue(XPathItem. java:372)
    ....
    ....

i dont know what the problem is .

Can anybody help ?

Nisarg Mehta