[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: Tue, 15 Nov 2005 17:30:47 +0000
recap: I'm trying to pass XML through to a param in my stylesheet. I'm using Xalan.

When I do this :-

transformer.setParameter(param.name, param.value);

where param.name and param.value are both Strings and contain - "inboundXML" and "<Numbers><Odds><One>1</One>... "

and when the stylesheet looks like this :-

...
 <xsl:param name="inboundXML" select="/"/>
 <xsl:template match="/">
   <rootContainer>
       <xsl:copy-of select="$inboundXML"/>
   </rootContainer>
 </xsl:template>
...

I get this (almost correct but no cigar :-) :-

<rootContainer>
       &lt;Numbers&gt;&lt:Odds&gt;&lt;One&gt;1.....
</rootContainer>


Previously Michael commented :-


Michael> Xalan, like Saxon, uses the setParameter() method on the JAXP javax.xml.transform.Transformer class.

Michael> However, the JAXP API doesn't actually say what kind of object you can
Michael> supply as the value. Most products will allow you to supply a DOM node (they
Michael> may restrict which DOM implementations you are allowed to use). Saxon allows
Michael> you to supply any JAXP Source object, so if you supply a StreamSource
Michael> containing raw XML, the XML will be parsed and the stylesheet will see the
Michael> resulting document node as the parameter value.


That's interesting I thought so I tried doing this (admittedly I'm not using Saxon (sorry Michael) so no guarantees) :-

transformer.setParameter(param.name, new StreamSource(new StringReader(param.value)));

but unfortunately all that gave me was :-

<rootContainer>javax.xml.transform.stream.StreamSource@4c6ca8b6</rootContainer>

I have tried using the exslt:node-set function, but I'm not sure I got it correct.

I would welcome any suggestions and perhaps a small example ?

Cheers

Fraser.

Current Thread