Hi everybody,
I'm working since many years with Cocoon 2.1 within a Tomcat server and
I need now to inject the content of my XML files in a MySQL database.
The problem is I have some XML elements (MySQL columns) that do contain
HTML tags (some "<br/>", "<i>...</i>" and a few "<a href url="..."/>).
For now, all tags seem simply to be trimmed away from my output.
Is there a way to inject tags in a text field from Cocoon 2.1 into MySQL
using <sql:execute-query>?
My database connection is defined as following in WEB-INF/cocoon.xconf:
<jdbc name="dautrepart">
<pool-controller min="1" max="10"/>
<dburl>jdbc:mysql://localhost:3306/dautrepart</dburl>
<user>webapp</user>
<password>webapp</password>
</jdbc>
In the sitemap, I have these lines:
<map:match pattern="copier.html">
<map:generate type="xpathdirectory"
src="../bac_a_sable/textes" label="content">
<map:parameter name="xpath" value="/fiche"/>
<map:parameter name="include" value=".xml"/>
</map:generate>
<map:transform src="nettoyer_structure.xslt"
label="debug01"/>
<map:transform src="preparer_sql.xslt" label="debug02"/>
<map:transform src="injection.xslt" label="requetes"/>
<map:transform type="sql">
<map:parameter name="use-connection"
value="dautrepart"/>
</map:transform>
<map:serialize type="xml"/>
</map:match>
And concerned parts of my stylesheet appears as follow:
<sql:execute-query>
<sql:query name="inserer_auteur">
<xsl:text>INSERT INTO auteur (nom, prenom,
identifiant, biographie, portrait_petit) VALUES ("</xsl:text>
<xsl:value-of select="identite/nom"/>
<xsl:text>", "</xsl:text>
<xsl:value-of select="identite/prenom"/>
<xsl:text>", "</xsl:text>
<xsl:value-of select="identite/@id"/>
<xsl:text>", "</xsl:text>
<xsl:apply-templates select="bio"/>
<xsl:text>", "</xsl:text>
<xsl:value-of select="identite/portrait"/>
<xsl:text>")</xsl:text>
</sql:query>
</sql:execute-query>
<xsl:template match="bio">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="i">
<i>
<xsl:apply-templates/>
</i>
</xsl:template>
An extract of the file I have:
<fiche>
<identiteid="boissier_laurence">
<nom>Boissier</nom>
<prenom>Laurence</prenom>
<portrait>boissier_laurence_150x100.png</portrait>
</identite>
<bio>
Née en 1965, elle habite dans le canton de Genève. Participe à Bern ist
überall et au cd
<i>Renens (VD)</i>
. Prix suisse de littérature 2017 pour
<i>Inventaire des lieux</i>
paru chez art&fiction.
<br/>
</bio>