Hi,
I have a xslt file I used following
java code to transform it .I want to retrieve each node in XSLT as an object or collection of objects and pass them as parameters to other Java code.
Is it possible to retrieve values without passing them to stream or Is there any other alternative way to do that
XML DOCUMENT
<sample>
<directory >
<name>c:\abc\fgfg</name>
<textfilespec>".txt"</textfilespec>
<filespec>".csv"</filespec>
<processing.filesuffix>.txt</processing.filesuffix>
<finishsuffix>.csv</finishsuffix>
</directory>
</sample>
XSLT file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2004/07/xpath-functions" xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes">
<xsl utput method="text/html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="sample/directory">
<xsl:text>DIRECTORY NAME:</xsl:text>
<xsl:value-of select="name"/>
<xsl:text>TEXT FILE: </xsl:text>
<xsl:value-of select="textfilespec"/>
<xsl:text>csv FILE:</xsl:text>
<xsl:value-of select="filespec"/>
<xsl:text>FILE SUFFIX:</xsl:text>
<xsl:value-of select="processing.filesuffix"/>
<xsl:text>FINISH SUFFIX</xsl:text>
<xsl:value-of select="finishsuffix"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
public static void main(
String[] args) throws TransformerException {
if (args.length != 2) {
System.err.println("Usage:"+" [xmlFileName] [xsltFileName]");
System.exit(1);
}
File xmlFile = new File(args[0]);
File xsltFile = new File(args[1]);
Source xmlSource = new StreamSource(xmlFile);
Source xsltSource = new StreamSource(xsltFile);
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
Result result = new StreamResult("C:/XSLT.txt");
System.out.println(result);
trans.transform(xmlSource, result);
trans.transform(xmlSource, new StreamResult(System.out));
}
Thanks in advance
[ December 15, 2005: Message edited by: bhargavi kakarala ]