Hi, im havinf some trouble creating a Generator in XSP and after that aplying a transformer in XSL, the problem is, that i am not able to parse the XML returned by the generator with the transformer.
---------------------------------------------------------------------------- ---------- Generator code
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
<xsp:structure> <xsp:include>pt.laseeb.dae.xmlDbApi.daeXmlDbApi</xsp:include> <xsp:include>org.xmldb.api.base.ResourceIterator</xsp:include> <xsp:include>org.xmldb.api.base.Resource</xsp:include> <xsp:include>org.xmldb.api.base.XMLDBException</xsp:include> </xsp:structure>
<document> <xsp:logic> try { Resource res = null; String resStr = null; daeXmlDbApi daeApi = new daeXmlDbApi(); ResourceIterator results; results = daeApi.getArticleSection("1").getIterator(); while (results.hasMoreResources()) { res = results.nextResource(); <contents><xsp:expr> (String)res.getContent()</xsp:expr></contents> } } catch(Exception e) { } </xsp:logic>
</document> </xsp:page>
Here you have <document/> as root element.
---------------------------------------------------------------------------- ----------
daeAPI is a API created by me to access to an XINDICE database that contains XML following the current syntax:
<article> <title></title> <text></text> <image></image> </article>
---------------------------------------------------------------------------- ---------- Transformer code
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="no" method="html" omit-xml-declaration = "yes" />
<xsl:template match="/"> <xsl:apply-templates /> </xsl:template>
<xsl:template match="/contents">
<xsl:for-each select = "/article" >
<titulo><xsl:value-of disable-output-escaping = "yes" select = "/title" /></titulo> <imagem><xsl:value-of disable-output-escaping = "yes" select = "/image" /></imagem>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Here you match on <contents/> as root element. Try to remove the line <xsl:output/> or at least make it correct: you don't want html as result of this transformation. Furthermore does the XSP code return XML or a string of the database content, that should be XML. Fix it there. Don't use disable-output-escaping.
Joerg
---------------------------------------------------------------------------- ------
and the problem is that what i get in the view source of the browser is something like,
<?xml version="1.0"?> <article id="1" rating="2" sectionid="1" xmlns:src="http://xml.apache.org/xindice/Query" src:col="/db/daeDocuments" src:key="1"> <title>Titulo com rating 2</title> <text>Texto</text> </article><?xml version="1.0"?> <article id="2" rating="1" sectionid="1" xmlns:src="http://xml.apache.org/xindice/Query" src:col="/db/daeDocuments" src:key="2"> <title>Titulo do artigo com rating igual a 1</title> <text>texto do artigo com rating igual a 1</text> <image>img1.jpg</image> </article><?xml version="1.0"?> <article id="3" rating="2" sectionid="1" xmlns:src="http://xml.apache.org/xindice/Query" src:col="/db/daeDocuments" src:key="3"> <title>Titulo do artigo com rating igual a 2</title> <text>texto do artigo com rating igual a 2</text> <image>img1.jpg</image> </article><?xml version="1.0"?> <article id="4" rating="2" sectionid="1" xmlns:src="http://xml.apache.org/xindice/Query" src:col="/db/daeDocuments" src:key="4"> <title>Titulo do artigo com rating igual a 2</title> <text>texto do artigo com rating igual a 2</text> <image>img1.jpg</image> </article>
and i con't parse it in my transformer.
If anyone could give a look at the code and see what i am doing wrong i would apreciate it :)
Thanks id advance Miguel Carvalho
