[XSLT] Recursivité et insertion
Bonjour,
Tout d'abord merci de prendre le temps de lire le message et d'essayer d'y repondre, car je suis vraiment en galère...
Voici l'interrogation :
Je dispose d'une bibliothèque sous ce format :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| <?xml version="1.0" encoding="utf-8"?>
<bookcases>
<bookcase name="a">
<shelf>
<pos>1</pos>
<type>small</type>
<width>600</width>
</shelf>
<shelf>
<pos>2</pos>
<type>medium</type>
<width>600</width>
</shelf>
<shelf>
<pos>3</pos>
<type>medium</type>
<width>600</width>
</shelf>
<shelf>
<pos>4</pos>
<type>medium</type>
<width>600</width>
</shelf>
<shelf>
<pos>5</pos>
<type>large</type>
<width>600</width>
</shelf>
<shelf>
<pos>6</pos>
<type>large</type>
<width>600</width>
</shelf>
</bookcase>
<bookcase name="b">
<shelf>
<pos>1</pos>
<type>small</type>
<width>600</width>
</shelf>
<shelf>
<pos>2</pos>
<type>small</type>
<width>600</width>
</shelf>
<shelf>
<pos>3</pos>
<type>medium</type>
<width>600</width>
</shelf>
<shelf>
<pos>4</pos>
<type>large</type>
<width>600</width>
</shelf>
<shelf>
<pos>5</pos>
<type>large</type>
<width>600</width>
</shelf>
<shelf>
<pos>6</pos>
<type>large</type>
<width>600</width>
</shelf>
</bookcase>
<bookcase name="c">
<shelf>
<pos>1</pos>
<type>medium</type>
<width>600</width>
</shelf>
<shelf>
<pos>2</pos>
<type>medium</type>
<width>600</width>
</shelf>
<shelf>
<pos>3</pos>
<type>medium</type>
<width>600</width>
</shelf>
<shelf>
<pos>4</pos>
<type>medium</type>
<width>600</width>
</shelf>
<shelf>
<pos>5</pos>
<type>medium</type>
<width>600</width>
</shelf>
<shelf>
<pos>6</pos>
<type>large</type>
<width>600</width>
</shelf>
</bookcase>
</bookcases> |
Et d'une liste de livre classifiée et ordonnée comme suit :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <?xml version='1.0' ?>
<mandybooks>
<class name="music" size="586" typeOfShelf="large">
<book class="music">
<author>vernon, Paul</author>
<title>A History of the Portuguese Fado</title>
<type>Medium</type>
</book><book class="music">
<author>Russell, Bill</author>
<title>Bill Russell's American Music</title>
<type>Large</type>
</book><book class="music">
<author>Vail, Ken</author>
<title>Bird's Diaries</title>
<type>Large</type>
</book>
....
</class
<class name="history usa" size="493" typeOfShelf="large"><book class="history usa">
<book>...</book>
...
</class>
...
<class name="mystery" size="591" typeOfShelf="medium"><book class="mystery">
<book>...</book>
...
</class>
<class name="humour" size="507" typeOfShelf="medium"><book class="humour">
<book>...</book>
...
</class>
<class name="mystery australia" size="495" typeOfShelf="small"><book class="mystery australia">
<book>...</book>
...
</class>
<class name="mystery italy" size="225" typeOfShelf="small"><book class="mystery italy">
<book>...</book>
...
</class>
</mandybooks> |
Le but est de loader chaque élement class dans les éléments shelf du premier document (un <class ne peut jamais etre coupé en deux et l'attribut typeOfShelf doit correspondre à l'attribut type de l'élement <shelf> où il doit etre loadé).
Ma première technique a été de créer un template qui peut créer un groupe de N class dont la somme des attributs size tient dans une taille fixée, en utilisant la recursion basique.
J'avoue que je suis à présent perdu, puisqu'une fois qu'on a parcouru tous les <class> et qu'on doit passer à l'étagère suivante, on doit se souvenir des étagères qui ont été remplies et des <class> qui ont été déjà rangées.
On m'a assuré que la solution restait simple à mettre en oeuvre, mais j'avoue que je patauge vraiment ... (Je ne suis pas tres bon en XSLT certes, mais 1 semaines sans avancer, c'est difficile ...)
Merci d'avance pour ceux qui réfléchiront à mon problème.