[xsl] Subject: RE: [xsl] XML fragment as a param ?

Subject: [xsl] Subject: RE: [xsl] XML fragment as a param ?
From: "Fraser Goffin" <goffinf@xxxxxxxxxxx>
Date: Wed, 16 Nov 2005 09:27:31 +0000
Fraser>recap: I'm trying to pass XML through to a param in my stylesheet. I'm using Xalan.
Fraser>
Fraser>When I do this :-
Fraser>
Fraser>transformer.setParameter(param.name, param.value);
Fraser>
Fraser>where param.name and param.value are both Strings and contain - "inboundXML" Fraser>and "<Numbers><Odds><One>1</One>... "
Fraser>
Fraser>I get this (almost correct but no cigar :-) :-
Fraser>
Fraser><rootContainer>&lt;Numbers&gt;&lt:Odds&gt;&lt;One&gt;1.....</rootContainer>
Fraser>


Nick,

thanks for your helpful response.

As you point out, if the XML I wanted to set as the param was already in a DOM I could indeed pass the DOM itself or a node selected from it. Unfortunately it isn't and the amount of XML is large so I didn't really want to have to load up a DOM simply to pass it through to an XSLT processor (I do use this technique in other places but only if the the data is already conveniently packaged or the amount of data is small).

Yes, I had thought of setting the output escaping, but am pretty reluctant to take that route for the reasons you mention (it is quite likely that the XML I'm passing in contains content that needs to be escaped).

Fraser> transformer.setParameter(param.name, new StreamSource(new
Fraser> StringReader(param.value)));
Fraser>
Fraser> but unfortunately all that gave me was :-
Fraser>
Fraser>
Fraser> <rootContainer>javax.xml.transform.stream.StreamSource@4c6ca8b6</rootContainer>


Nick> Which is also correct (in your environment) as that is the string
Nick> representation of the StreamSource: clearly the processor you are using
Nick> doesn't support using a StreamSource as a parameter, and so took the
Nick> result of that object's toString() method.


Oh, ok, thanks for clearing that up.

The 'HowTo' on exslt:node-set suggest that it can create a node set from a text() node, but I'm not sure a 'string' parameter (especially one that has been 'escaped') qualifies. In any event I couldn't get it to co-operate.

I have written a URI Resolver so I can pass my data in through the document() function, but I wanted cake (and eat it) by being able to have 2 options to provide this XML to the stylesheet (just greedy I guess :-)

Thanks

Fraser.

Current Thread