Diaporama

On souhaite réaliser une chaîne éditoriale XML permettant de créer et publier des diaporamas.

Soit l'exemple représentatif de contenu suivant :

Question

Réaliser le modèle conceptuel du document avec UML.

Solution

Modèle UML

Question

Réaliser le schéma XML du document avec RelaxNG.

Question

Rédiger un exemple de contenu XML valide par rapport au schéma.

Question

Écrivez un programme XSL-XSLT qui permet de transformer une diapositive de type diapoImage en XHTML.

Pour ce premier programme simple on pourra écrire un seul template et l'on utilisera les XPATH pour remplir le patron XHTML.

Pour le corps du XHTML on pourra utiliser les balises h1 et img.

Indice

Structure XHTML visée :

1
<html xmlns="http://www.w3.org/1999/xhtml"> 
2
    <head>
3
        <title>...</title>
4
    </head>
5
    <body>
6
        <h1>...</h1>
7
        <img src="..."/>
8
    </body>
9
</html>

Programme XSLT à finir de remplir (remplacer les __XPATH__).

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet 
3
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
4
    xmlns:td="http://utc.fr/nf29/td"
5
    xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="td" version="1.0">
6
    <xsl:output method="html" encoding="UTF-8"/>
7
    <xsl:template match="/">
8
        <html>
9
            <head>
10
                <title><xsl:value-of select="__XPATH__"/></title>
11
            </head>
12
            <body>
13
                <h1><xsl:value-of select="__XPATH__"/></h1>
14
                <img src="{__XPATH__}"/>
15
            </body>
16
        </html>
17
    </xsl:template>
18
</xsl:stylesheet>

Solution

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet 
3
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
4
    xmlns:td="http://utc.fr/nf29/td"
5
    xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="td" version="1.0">
6
    <xsl:output method="html" encoding="UTF-8"/>
7
    <xsl:template match="/">
8
        <html>
9
            <head>
10
                <title><xsl:value-of select="./td:diapoImage/td:titre"/></title>
11
            </head>
12
            <body>
13
                <h1><xsl:value-of select="./td:diapoImage/td:titre"/></h1>
14
                <img src="{./td:diapoImage/td:contenu/td:image/td:source}"/>
15
            </body>
16
        </html>
17
    </xsl:template>
18
</xsl:stylesheet>

Question

Écrivez un programme XSL-XSLT qui permet de transformer une diapositive de type diapoTexte en XHTML.

Indice

Écrivez six templates, un pour la racine /, un pour diapoTexte, un pour liste, un pour item, un pour paragraphe et un pour important.

Pour le XHTML, vous pourrez utiliser ul, li, p et b.

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:td="http://utc.fr/nf29/td"
3
    xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="td" version="1.0">
4
    <xsl:output method="html" encoding="UTF-8"/>
5
    <xsl:template match="/">
6
        <html>
7
            <head>
8
                <title><xsl:value-of select="__XPATH__"/></title>
9
            </head>
10
            <body>
11
                <xsl:apply-templates select="__XPATH__"/>
12
            </body>
13
        </html>
14
    </xsl:template>
15
    <xsl:template match="td:diapoTexte">
16
        <h1><xsl:value-of select="__XPATH__"/></h1>
17
        <xsl:apply-templates select="__XPATH__"/>
18
        <h2>Conclusion</h2>
19
        <xsl:apply-templates select="__XPATH__"/>
20
    </xsl:template>
21
    <xsl:template match="td:liste"> __XSLT__ </xsl:template>
22
    <xsl:template match="td:item"> __XSLT__ </xsl:template>
23
    <xsl:template match="td:paragraphe"> __XSLT__ </xsl:template>
24
    <xsl:template match="td:important"> __XSLT__ </xsl:template>
25
</xsl:stylesheet>

Question

Écrivez un programme XSL-XSLT qui permet de transformer un diaporama complet en un unique fichier XHTML.

Indice

Utiliser la fonction document().

1
<xsl:template match="td:diaporama">
2
    ...
3
    <xsl:apply-templates select="document(./td:refPartie)/td:partie"/>
4
    ...
5
</xsl:template>

Question

Ajouter au programme précédent la génération préalable d'un sommaire avec des ancres.

Indice

Utiliser :

  • La commande xsl:foreach pour le sommaire ;

  • la fonction generate-id dans la balise <a href="#{generate-id(.)}"> pour les liens sources ;

  • la fonction generate-id dans la balise <h2 id="{generate-id(.)}"><xsl:value-of select="./td:titre"/></h2> pour les ancres cibles.

1
<xsl:template match="td:diaporama"> ... <h2>Table des matières</h2>
2
    <xsl:for-each select="document(./td:refPartie)/td:partie">
3
        <p><a href="#{generate-id(.)}"><xsl:value-of select="./td:titre"/></a></p><xsl:for-each
4
            select="document(./td:refDiapo)/*">
5
            <li><a href="#{generate-id(.)}"><xsl:value-of select="./td:titre"/></a></li>
6
        </xsl:for-each>
7
    </xsl:for-each> 
8
    ... 
9
</xsl:template>
1
<xsl:template match="td:partie"> 
2
  ...
3
  <h2 id="{generate-id(.)}"><xsl:value-of select="./td:titre"/></h2>
4
  ...
5
</xsl:template>