Probleme Récursivité XML/XSLT

englandoxford Messages postés 3 Date d'inscription mardi 23 mars 2010 Statut Membre Dernière intervention 24 mars 2010 - 23 mars 2010 à 11:57
englandoxford Messages postés 3 Date d'inscription mardi 23 mars 2010 Statut Membre Dernière intervention 24 mars 2010 - 24 mars 2010 à 09:25
Bonjour a tous, amis internautes, me voici totalement bloqué dans la rédaction d'un fichier XSL permettant un tri depuis une base de données, vers une seconde, en utilisant la récursivité. Ce probleme est assez complexe et le challenge est assez intéressant, seuls les plus doués d'entre vous en viendront a bout ! Pour ma part...je n'y arrive pas..!

(je tape depuis un clavier anglophone donc je n'aurai pas tous les accents, désolé!)

Voici l'énoncé:

J'ai différentes classes regroupant toutes une série de livres. Celles ci sont classées dans trois catégories étant Small, Medium et Large. Celles qui sont Larges contiennent au moins un livre de width "épaisseur" Large, celles dans Medium n'ont que des livres d'épaisseur medium ou small et dans la Small, sont répertoriés des livres d'épaisseur small uniquement. Dans cette premiere base de données, il y aussi des Shelf (étageres) dans lesquelles il faudra justement classer toutes ces classes de différentes épaisseurs. Il existe des shelf pouvant contenir des classes de type Larges, Medium et small (shelf de type "Large"), celles qui peuvent contenir des classes de type Medium et Small (shelf de type "Meidum") et celles qui ne contiennent que des classes Small (shelf de type "Small").

Vous l'aurez compris, l'idée est de regrouper ces classes dans les Shelf (ayant tous une épaisseur de 600), utilisant la récursivité, sans qu'aucune classe ne soit coupée entre deux étageres.
(les classes regroupes des livres de différentes épaisseurs et lépaisseur de la classe est égale a la somme des épaisseurs de chaque livre, le but est que dans une shelf la somme des épaisseurs de claque classe ne dépasse pas 600 unités de "width")

J'ai fait une bonne partie du travail mais, rien a faire, je n'arrive pas a terminer....Je vous ai collé plus bas la base de données (.xml) et le travail que j'ai fait (.xsl)

Merci aux intéressés de vous pencher sur le sujet.

Mon mail est disponible si vous voulez m'envoyer une solution par mail...

Cordialement.

Englandoxford.

-----------
code XSL:


<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl "http://www.w3.org/1999/XSL/Transform" version "1.1" > <xsl:output method="xml" indent="yes"/>

<xsl:template match="mandybooks">
<mandybooks>
<!--
<orig>
<xsl:copy-of select="*"/>
</orig>
-->
<xsl:call-template name="loadclass">
<xsl:with-param name="shelves" select="shelves/bookcase/shelf"/>
<xsl:with-param name="classes" select="classes/hgroup/class"/>
</xsl:call-template>
</mandybooks>
</xsl:template>




<xsl:template name="loadclass">
<xsl:param name="shelves"/>
<xsl:param name="classes"/>
<xsl:choose>

<xsl:when test="not($classes)"/>
<xsl:otherwise>

<xsl:variable name="classwidth" select="$classes[1]/@size"></xsl:variable>
<xsl:variable name="bookcase" select="$shelves[@width > $classwidth][1]/@name"/>




<xsl:variable name="newshelves">
<shelves>




<xsl:for-each select="$shelves">

<xsl:choose>


<xsl:when test="$classes[1]/@shelf='large'">

<xsl:choose>

<xsl:when test="@name != $bookcase"><xsl:copy-of select="."/></xsl:when>
<xsl:when test="type='large'">

<xsl:copy>

<xsl:copy-of select="@* [name() != 'width']"/>
<xsl:attribute name="width"><xsl:value-of select="@width - $classwidth"/></xsl:attribute>
<xsl:copy-of select="*" />
<xsl:copy-of select="$classes[1]"/>

</xsl:copy>
</xsl:when>
<xsl:when test="type='medium'">
<xsl:copy>

<xsl:copy-of select="."/>

</xsl:copy>
</xsl:when>
<xsl:when test="type='small'">
<xsl:copy>

<xsl:copy-of select="."/>

</xsl:copy>
</xsl:when>

<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>

</xsl:choose>

</xsl:when>
<xsl:when test="$classes[1]/@shelf='medium'">
<xsl:choose>
<xsl:when test="@name != $bookcase"><xsl:copy-of select="."/></xsl:when>
<xsl:when test="type='large'">
<xsl:copy>

<xsl:copy-of select="@* [name() != 'width']"/>
<xsl:attribute name="width"><xsl:value-of select="@width - $classwidth"/></xsl:attribute>
<xsl:copy-of select="*" />
<xsl:copy-of select="$classes[1]"/>

</xsl:copy>
</xsl:when>

<xsl:when test="type='medium'">
<xsl:copy>

<xsl:copy-of select="@* [name() != 'width']"/>
<xsl:attribute name="width"><xsl:value-of select="@width - $classwidth"/></xsl:attribute>
<xsl:copy-of select="*" />
<xsl:copy-of select="$classes[1]"/>

</xsl:copy>
</xsl:when>

<xsl:when test="type='small'">
<xsl:copy>

<xsl:copy-of select="."/>

</xsl:copy>
</xsl:when>

<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>

</xsl:choose>
</xsl:when>


<xsl:when test="$classes[1]/@shelf='small'">
<xsl:choose>
<xsl:when test="@name != $bookcase"><xsl:copy-of select="."/></xsl:when>
<xsl:when test="type='large'">
<xsl:copy>

<xsl:copy-of select="@* [name() != 'width']"/>
<xsl:attribute name="width"><xsl:value-of select="@width - $classwidth"/></xsl:attribute>
<xsl:copy-of select="*" />
<xsl:copy-of select="$classes[1]"/>

</xsl:copy>
</xsl:when>
<xsl:when test="type='medium'">
<xsl:copy>

<xsl:copy-of select="@* [name() != 'width']"/>
<xsl:attribute name="width"><xsl:value-of select="@width - $classwidth"/></xsl:attribute>
<xsl:copy-of select="*" />
<xsl:copy-of select="$classes[1]"/>

</xsl:copy>
</xsl:when>
<xsl:when test="type='small'">
<xsl:copy>

<xsl:copy-of select="@* [name() != 'width']"/>
<xsl:attribute name="width"><xsl:value-of select="@width - $classwidth"/></xsl:attribute>
<xsl:copy-of select="*" />
<xsl:copy-of select="$classes[1]"/>

</xsl:copy>
</xsl:when>

<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>

</xsl:choose>

</xsl:when>

<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>

</xsl:choose>


</xsl:for-each>



</shelves>
</xsl:variable>



<xsl:variable name="newclasses">
<classes>
<xsl:copy-of select="$classes[position() != 1]"/>
</classes>
</xsl:variable>

<move>
<xsl:copy-of select="$newshelves" />
<xsl:copy-of select="$newclasses"/>
</move>


<xsl:call-template name="loadclass">
<xsl:with-param name="shelves" select="$newshelves/shelves/shelf"/>
<xsl:with-param name="classes" select="$newclasses/classes/class"/>
</xsl:call-template>


</xsl:otherwise>
</xsl:choose>
</xsl:template>



</xsl:stylesheet>

--------------------------------------





---------------------
code XML:

<?xml version="1.0" encoding="UTF-8"?>
<mandybooks>
<classes>
<hgroup id="small">
<class name="mystery australia" size="465" shelf="small"/>
<class name="mystery north" size="270" shelf="small"/>
<class name="mystery italy" size="225" shelf="small"/>
<class name="fiction general" size="210" shelf="small"/>
<class name="systems" size="200" shelf="small"/>
<class name="mystery oxford" size="180" shelf="small"/>
<class name="mystery parks" size="135" shelf="small"/>
<class name="biography sport" size="129" shelf="small"/>
<class name="sport" size="120" shelf="small"/>
<class name="web early" size="114" shelf="small"/>
<class name="animation early" size="105" shelf="small"/>
<class name="mystery france" size="90" shelf="small"/>
<class name="history usa-indian" size="69" shelf="small"/>
<class name="mystery spain" size="30" shelf="small"/>
</hgroup>
<hgroup id="large">
<class name="mystery indian" size="595" shelf="large"/>
<class name="music" size="590" shelf="large"/>
<class name="history english" size="394" shelf="large"/>
<class name="biography general" size="380" shelf="large"/>
<class name="markup" size="290" shelf="large"/>
<class name="nonfiction general" size="185" shelf="large"/>
<class name="reference" size="165" shelf="large"/>
<class name="animation general" size="160" shelf="large"/>
<class name="history usa" size="NaN" shelf="large"/>
</hgroup>
<hgroup id="medium">
<class name="mystery general" size="580" shelf="medium"/>
<class name="humour" size="570" shelf="medium"/>
<class name="biography musician" size="505" shelf="medium"/>
<class name="programming" size="475" shelf="medium"/>
<class name="xslt" size="400" shelf="medium"/>
<class name="history uscivilwar" size="370" shelf="medium"/>
<class name="web graphics" size="365" shelf="medium"/>
<class name="biography jazz" size="365" shelf="medium"/>
<class name="web general" size="275" shelf="medium"/>
<class name="history science" size="210" shelf="medium"/>
<class name="history general" size="200" shelf="medium"/>
<class name="xml" size="175" shelf="medium"/>
<class name="flight" size="174" shelf="medium"/>
<class name="styling" size="150" shelf="medium"/>
<class name="graphics" size="50" shelf="medium"/>
</hgroup>
</classes>
<shelves>

<shelf name="a1" width="600">
1


<type>small</type>
<width>600</width>
<height>40</height>
</shelf>
<shelf name="a2" width="600">
2


<type>medium</type>
<width>600</width>
<height>60</height>
</shelf>
<shelf name="a3" width="600">
3


<type>medium</type>
<width>600</width>
<height>60</height>
</shelf>
<shelf name="a4" width="600">
4


<type>medium</type>
<width>600</width>
<height>60</height>
</shelf>
<shelf name="a5" width="600">
5


<type>large</type>
<width>600</width>
<height>80</height>
</shelf>
<shelf name="a6" width="600">
6


<type>large</type>
<width>600</width>
<height>80</height>
</shelf>


<shelf name="b1" width="600">
1


<type>small</type>
<width>600</width>
<height>40</height>
</shelf>
<shelf name="b2" width="600">
2


<type>medium</type>
<width>600</width>
<height>60</height>
</shelf>
<shelf name="b3" width="600">
3


<type>medium</type>
<width>600</width>
<height>60</height>
</shelf>
<shelf name="b4" width="600">
4


<type>medium</type>
<width>600</width>
<height>60</height>
</shelf>
<shelf name="b5" width="600">
5


<type>large</type>
<width>600</width>
<height>80</height>
</shelf>
<shelf name="b6" width="600">
6


<type>large</type>
<width>600</width>
<height>80</height>
</shelf>



<shelf name="c1" width="600">
1


<type>small</type>
<width>600</width>
<height>40</height>
</shelf>
<shelf name="c2" width="600">
2


<type>medium</type>
<width>600</width>
<height>60</height>
</shelf>
<shelf name="c3" width="600">
3


<type>medium</type>
<width>600</width>
<height>60</height>
</shelf>
<shelf name="c4" width="600">
4


<type>medium</type>
<width>600</width>
<height>60</height>
</shelf>
<shelf name="c5" width="600">
5


<type>large</type>
<width>600</width>
<height>80</height>
</shelf>
<shelf name="c6" width="600">
6


<type>large</type>
<width>600</width>
<height>80</height>
</shelf>

</shelves>
</mandybooks>


-------------------------------------------------

1 réponse

englandoxford Messages postés 3 Date d'inscription mardi 23 mars 2010 Statut Membre Dernière intervention 24 mars 2010
24 mars 2010 à 09:25
Salut a tous c'est toujours moi, je voulais juste vous dire que j'avais résolu mon soucis, donc c'est bon, merci à tous ceux qui se sont penchés sur le sujet
0
Rejoignez-nous