Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load Transformation Wihout Using XSL File??

Status
Not open for further replies.

bchagnon

Programmer
Oct 3, 2002
4
0
0
CA
I have a string containing the xsl sequence.

XPathNavigator nav = root.CreateNavigator();
// Transform the file.
XslTransform xslt = new XslTransform();
StringWriter swXml = new StringWriter();
xslt.Load(????);

is there a fonction like LoadXsl or someting like that?

I don't want to use a xsl file.

thanks you

Benoît Chagnon
Posera Software
 
In java (which i think is what you're using although prolly a different xslt transformer package to me, i use JDOM) you have to convert the string into an StringReader object like this:

String xmlstring=&quot;<xsl:stylesheet/>&quot;;

StringReader sr = new StringReader(xmlstring);

Then u can use the xml transformer as before with the reader as the StreamSource:

Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(sr));

//transform

org.jdom.transform.JDOMResult result = new org.jdom.transform.JDOMResult();
transformer.transform(new org.jdom.transform.JDOMSource(xml), result);
//output
op.output(result.getDocument().getRootElement(), out);

phew :)

This may, as i said, be different for you. The only problems i can forsee with this is that you wont have control over how the xml is formed this way. You could pass it through a SAXBuilder but this may be too cumbersome for you.
Failing this, or if you're not using java, remember that an XSLT stylesheet is just an XML document and can be treated like one in all respects.


Any questions just ask.

matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top