13.07.2013 Views

dans des entrepôts de données XML - CoDE - Université Libre de ...

dans des entrepôts de données XML - CoDE - Université Libre de ...

dans des entrepôts de données XML - CoDE - Université Libre de ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPITRE 6. GÉNÉRATEUR AUTOMATIQUE DE FICHIER XSLT 39<br />

6.5.2 Co<strong>de</strong> XSLT selon la transformation <strong>de</strong>mandée<br />

Dans ce paragraphe, nous présentons une façon <strong>de</strong> générer le co<strong>de</strong> XSLT selon le type <strong>de</strong><br />

transformation choisie par l’utilisateur. Nous signalons tout <strong>de</strong> suite que <strong>dans</strong> le prototype<br />

que nous avons développé, nous n’avons couvert que quelques configurations <strong><strong>de</strong>s</strong> transformations.<br />

Notre objectif étant <strong>de</strong> montrer tout simplement la faisabilité <strong>de</strong> générer un XSLT<br />

automatiquement. Pour un ETL à mettre en production, il faut essayer <strong>de</strong> couvrir au mieux<br />

les types <strong><strong>de</strong>s</strong> conversions possibles.<br />

Nous avons implémenté les cas <strong><strong>de</strong>s</strong> transformations suivantes.<br />

– Transformation d’un élément en un autre élément.<br />

– Transformation <strong><strong>de</strong>s</strong> attributs (que l’élément lui-même soit transformé ou pas).<br />

– Transformation <strong><strong>de</strong>s</strong> éléments <strong><strong>de</strong>s</strong>cendants.<br />

Dans le co<strong>de</strong> du listing 6.2, on utilise, notamment, les variables suivantes.<br />

elsrc est le nom <strong>de</strong> l’élément source à transformer éventuellement,<br />

eldst est le nom <strong>de</strong> l’élément <strong><strong>de</strong>s</strong>tination correspondant à la transformation,<br />

attribsrc est le nom <strong>de</strong> l’attribut qu’on veut transformer,<br />

attribdst est le nom <strong>de</strong> l’attribut/élément en quoi se transforme attribsrc,<br />

elsrclst est la liste <strong><strong>de</strong>s</strong> noms <strong><strong>de</strong>s</strong> éléments définis à la source,<br />

eldstlst est la liste <strong><strong>de</strong>s</strong> noms <strong><strong>de</strong>s</strong> éléments définis à la <strong><strong>de</strong>s</strong>tination.<br />

Listing 6.2 – Production du co<strong>de</strong> XSLT selon le type <strong>de</strong> transformation choisie<br />

while (" elsrclst is not empty ")<br />

{<br />

elsrc :=" the next elem in elsrclst ";<br />

eldst :=" corresponding elem in eldstlst ";<br />

fwrite ( filexsl ," < xsl : template match =\" elsrc \" >\n");<br />

// one founds an element called elsrc . What to do?<br />

if (" eldst is not empty ") then<br />

{<br />

fwrite ( filexsl ," < eldst >") ;<br />

// open the tag of the correspoding element<br />

}<br />

" Generate XSLT co<strong>de</strong> for translating attributes of elsrc , if nee<strong>de</strong>d ";<br />

// we have to check wether attributes should be transformed<br />

// even if the elemenent itself is not taken .<br />

if (" eldst is not empty ") then<br />

{<br />

fwrite ( filexsl ," < xsl : apply - templates / >\n");<br />

// apply template of children<br />

fwrite ( filexsl ," ") ;<br />

// close the tag of the <strong><strong>de</strong>s</strong>tination element .<br />

}<br />

else // there is no direct corresponding element<br />

{<br />

fwrite ( filexsl ," < xsl :if test =\" child ::*\" >\ n");<br />

// Test whether the current element has any children<br />

fwrite ( filexsl ," < xsl : apply - templates / >\n");<br />

// apply template of children

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!