[prev in list] [next in list] [prev in thread] [next in thread]
List: xml-cocoon-users
Subject: Is there a way to inject tags in a text field from Cocoon 2.1 into MySQL using sql:execute-query?
From: Philippe Faehndrich <phfaehndrich () bluewin ! ch>
Date: 2017-04-29 23:41:43
Message-ID: 1f736d6d-2e8c-9f7b-a730-7cacf3b77794 () bluewin ! ch
[Download RAW message or body]
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>
[Attachment #3 (text/html)]
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi everybody,<br>
<br>
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.<br>
<br>
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="..."/>).<br>
<br>
For now, all tags seem simply to be trimmed away from my output.<br>
<br>
Is there a way to inject tags in a text field from Cocoon 2.1 into
MySQL using <sql:execute-query>?<br>
<br>
My database connection is defined as following in
WEB-INF/cocoon.xconf:<br>
<br>
<jdbc name="dautrepart"><br>
<pool-controller min="1" max="10"/><br>
<dburl>jdbc:mysql://localhost:3306/dautrepart</dburl><br>
<user>webapp</user><br>
<password>webapp</password><br>
</jdbc><br>
<br>
In the sitemap, I have these lines:<br>
<br>
<map:match pattern="copier.html"><br>
<map:generate type="xpathdirectory"
src="../bac_a_sable/textes" label="content"><br>
<map:parameter name="xpath"
value="/fiche"/><br>
<map:parameter name="include"
value=".xml"/><br>
</map:generate><br>
<map:transform src="nettoyer_structure.xslt"
label="debug01"/><br>
<map:transform src="preparer_sql.xslt"
label="debug02"/><br>
<map:transform src="injection.xslt"
label="requetes"/><br>
<map:transform type="sql"><br>
<map:parameter name="use-connection"
value="dautrepart"/><br>
</map:transform><br>
<map:serialize type="xml"/><br>
</map:match><br>
<br>
And concerned parts of my stylesheet appears as follow:<br>
<br>
<sql:execute-query><br>
<sql:query name="inserer_auteur"><br>
<xsl:text>INSERT INTO auteur (nom,
prenom, identifiant, biographie, portrait_petit) VALUES
("</xsl:text><br>
<xsl:value-of select="identite/nom"/><br>
<xsl:text>", "</xsl:text><br>
<xsl:value-of
select="identite/prenom"/><br>
<xsl:text>", "</xsl:text><br>
<xsl:value-of select="identite/@id"/><br>
<xsl:text>", "</xsl:text><br>
<xsl:apply-templates select="bio"/><br>
<xsl:text>", "</xsl:text><br>
<xsl:value-of
select="identite/portrait"/><br>
<xsl:text>")</xsl:text><br>
</sql:query><br>
</sql:execute-query><br>
<br>
<xsl:template match="bio"><br>
<xsl:apply-templates/><br>
</xsl:template><br>
<br>
<xsl:template match="i"><br>
<i><br>
<xsl:apply-templates/><br>
</i><br>
</xsl:template><br>
<br>
An extract of the file I have:<br>
<br>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
<div class="line"><span class="html-tag"><fiche></span></div>
<div class="collapsible-content" style="margin-left: 1em;">
<div class="collapsible" id="collapsible371">
<div class="expanded">
<div class="line"><span class="button collapse-button"
style="user-select: none; cursor: pointer; display:
inline-block; margin-left: -10px; width: 10px; background:
url("data:image/svg+xml,<svg
xmlns='http://www.w3.org/2000/svg' fill='#909090'
width='10' height='10'><path d='M0 0 L8 0 L4 7
Z'/></svg>"); vertical-align: bottom;
height: 10px;"></span><span class="html-tag"><identite<span
class="html-attribute"><span
class="Apple-converted-space"> </span><span
class="html-attribute-name">id</span>="<span
class="html-attribute-value">boissier_laurence</span>"</span>></span></div>
<div class="collapsible-content" style="margin-left: 1em;"><span
class="text"></span>
<div class="line"><span class="html-tag"><nom></span><span
class="text">Boissier</span><span class="html-tag"></nom></span></div>
<span class="text"></span>
<div class="line"><span class="html-tag"><prenom></span><span
class="text">Laurence</span><span class="html-tag"></prenom></span></div>
<span class="text"></span>
<div class="line"><span class="html-tag"><portrait></span><span
class="text">boissier_laurence_150x100.png</span><span
class="html-tag"></portrait></span></div>
<span class="text"></span></div>
<div class="line"><span class="html-tag"></identite></span></div>
</div>
</div>
<div class="collapsible" id="collapsible372">
<div class="expanded">
<div class="line"><span class="button collapse-button"
style="user-select: none; cursor: pointer; display:
inline-block; margin-left: -10px; width: 10px; background:
url("data:image/svg+xml,<svg
xmlns='http://www.w3.org/2000/svg' fill='#909090'
width='10' height='10'><path d='M0 0 L8 0 L4 7
Z'/></svg>"); vertical-align: bottom;
height: 10px;"></span><span class="html-tag"><bio></span></div>
<div class="collapsible-content" style="margin-left: 1em;"><span
class="text">Née en 1965, elle habite dans le canton de
Genève. Participe à Bern ist überall et au cd</span>
<div class="line"><span class="html-tag"><i></span><span
class="text">Renens (VD)</span><span class="html-tag"></i></span></div>
<span class="text">. Prix suisse de littérature 2017 pour</span>
<div class="line"><span class="html-tag"><i></span><span
class="text">Inventaire des lieux</span><span
class="html-tag"></i></span></div>
<span class="text">paru chez art&fiction.</span>
<div class="line"><span class="html-tag"><br/></span></div>
<span class="text"></span></div>
<div class="line"><span class="html-tag"></bio></span></div>
</div>
</div>
<div class="collapsible" id="collapsible373">
<div class="expanded">
<div class="line"><span class="button collapse-button"
style="user-select: none; cursor: pointer; display:
inline-block; margin-left: -10px; width: 10px; background:
url("data:image/svg+xml,<svg
xmlns='http://www.w3.org/2000/svg' fill='#909090'
width='10' height='10'><path d='M0 0 L8 0 L4 7
Z'/></svg>"); vertical-align: bottom;
height: 10px; color: rgb(0, 0, 0); font-family: monospace;
font-size: 13px; font-style: normal;
font-variant-ligatures: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; orphans: 2;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; text-decoration-style:
initial; text-decoration-color: initial;"></span><span
class="html-tag" style="font-family: monospace; font-size:
13px; font-style: normal; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; orphans: 2; text-align: start;
text-indent: 0px; text-transform: none; white-space:
normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; text-decoration-style:
initial; text-decoration-color: initial;"><br
class="Apple-interchange-newline">
</span></div>
</div>
</div>
</div>
<br>
</body>
</html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic