XSL based XML Rendering

I am trying to display an XML string in a page. The XML has an XSL stylesheet embedded for formatting.

When I place the XML string in a
label
of type CONTENT_XML. However, it strips the XML tag and XSL stylesheet reference, before rendering.

The only other option I have considered is using an
embedded
component, probably a TYPE_BROWSER, and trying to render it that way, but I would have to stream my string into it, as the
embedded
component won’t take plain text based content.

Am I missing something simple in the
label
that will let me use it, or should I go down the
embedded
route?

Hi,

If you put XML in a Label, it is treated as an X(HT)ML fragment that is injected in the HTML tree by the browser, not an XML document. so the XML document header is stripped…

Do you really need to let the browser do the XSLT processing? How about processing it in the Vaadin app (on the server-side) with a processor such as Xalan or Saxon?

XSLT processing is AFAIK supported in all the major browsers supported by Vaadin, but is not universal and there might be incompatibilities, so processing it server-side probably enhances compatibility.

If you go with the Embedded component and you have your XML in a string, you’ll have to stream it to the Embedded using either a StreamResource (recommended) or an ExternalResource+UriHandler.

I actually tried going down that road earlier, however when I tried this :

       StreamResource sr = new StreamResource(new StreamResource.StreamSource() {
            @Override
              public InputStream getStream() {
                    return new StringInputStream(getClientEndpoint().getRecord(getWSRequest(ID)));
              }
        }, "text/xml", this);

        Embedded e = new Embedded("", sr);
        e.setType(Embedded.TYPE_BROWSER);
        e.setMimeType("text/xml");
        p.addComponent(e);

In Firefox I get a save dialog which saves the XML.

In IE I get :

		<iframe tabIndex="-1" id="__gwt_historyFrame" style="position:absolute;width:0;height:0;border:0;overflow:hidden;" src="javascript:false">
		</iframe>
		<script language='javascript' 
			src='/TestApp/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/com.vaadin.terminal.gwt.DefaultWidgetSet.nocache.js?1293841004747'>
		</script> 

Visible to the end user, Inside the iframe, along with a javascript error about being unable to load the defaultWidgetSet.

I do like the idea of the server-side transform, I may have to go that road. Thanks.