Jerome Louvel <contact <at> noelios.com> writes:
>
>
> Hi Serene,
>
> I'm not aware of such limitation. Are you sure that your XSLT stylesheet
> correctly deal with namespaces? Could you send us a reproducible sample?
>
> Best regards,
> Jerome
>
> > -----Message d'origine-----
> > De : news [mailto:news <at> ger.gmane.org] De la part de Serene
> > Envoyé : mercredi 27 février 2008 09:24
> > À : discuss <at> restlet.tigris.org
> > Objet : How to use Transformer with XML namespaces?
> >
> > Hi,
> >
> > I am trying to transform an XML with namespaces through XSL
> > to HTML. In my
> > DomRepresentation and DocumentBuilderFactory, I called
> > setNamespaceAware(true).
> > The TransformRepresentation does not seem to handle XML with
> > namespaces. I do
> > not see any way to set namespace awareness in
> > TransformRepresentation. How
> > should I be handling this? Is there something I am missing?
> >
> > Thanks,
> > Serene
> >
>
>
Hi,
Here is a sample:
Java code:
File file = new File("Simple.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(file);
Transformer transformer =
new Transformer(Transformer.MODE_RESPONSE,new FileRepresentation(
"sample.xsl",MediaType.TEXT_HTML,-1));
DomRepresentation dom = new DomRepresentation(MediaType.TEXT_HTML,doc);
dom.setNamespaceAware(true);
result = new TransformRepresentation(getContext(),dom,
new FileRepresentation("src/xml/sample.xsl",MediaType.TEXT_HTML,-1));
result.setMediaType(MediaType.TEXT_HTML);
Simple.xml:
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'
xmlns:gd='http://schemas.google.com/g/2005'>
<id>http://docs.google.com/feeds/documents/private/full</id>
<openSearch:totalResults>19</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<entry>
<id>http://docs.google.com/feeds/documents/private/full/document%3Adfcp67fj_14cz5qrw</id>
<updated>2006-12-11T04:09:31.661Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/docs/2007#document' label='document'/>
<title type='text'>Improvement</title>
</entry>
</feed>
Sample.xsl:
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:output method="html"/>
<xsl:template match="/feed">
<html>
<head>
<title>Sample</title>
</head>
<body>
<xsl:value-of select="entry/title"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Thanks,
Serene