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.
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 :
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>...</title>
</head>
<body>
<h1>...</h1>
<img src="..."/>
</body>
</html>
Programme XSLT à finir de remplir (remplacer les __XPATH__
).
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:td="http://utc.fr/nf29/td"
xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="td" version="1.0">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="__XPATH__"/></title>
</head>
<body>
<h1><xsl:value-of select="__XPATH__"/></h1>
<img src="{__XPATH__}"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Solution
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:td="http://utc.fr/nf29/td"
xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="td" version="1.0">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="./td:diapoImage/td:titre"/></title>
</head>
<body>
<h1><xsl:value-of select="./td:diapoImage/td:titre"/></h1>
<img src="{./td:diapoImage/td:contenu/td:image/td:source}"/>
</body>
</html>
</xsl:template>
</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
.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:td="http://utc.fr/nf29/td"
xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="td" version="1.0">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="__XPATH__"/></title>
</head>
<body>
<xsl:apply-templates select="__XPATH__"/>
</body>
</html>
</xsl:template>
<xsl:template match="td:diapoTexte">
<h1><xsl:value-of select="__XPATH__"/></h1>
<xsl:apply-templates select="__XPATH__"/>
<h2>Conclusion</h2>
<xsl:apply-templates select="__XPATH__"/>
</xsl:template>
<xsl:template match="td:liste"> __XSLT__ </xsl:template>
<xsl:template match="td:item"> __XSLT__ </xsl:template>
<xsl:template match="td:paragraphe"> __XSLT__ </xsl:template>
<xsl:template match="td:important"> __XSLT__ </xsl:template>
</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()
.
<xsl:template match="td:diaporama">
...
<xsl:apply-templates select="document(./td:refPartie)/td:partie"/>
...
</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.
<xsl:template match="td:diaporama"> ... <h2>Table des matières</h2>
<xsl:for-each select="document(./td:refPartie)/td:partie">
<p><a href="#{generate-id(.)}"><xsl:value-of select="./td:titre"/></a></p><xsl:for-each
select="document(./td:refDiapo)/*">
<li><a href="#{generate-id(.)}"><xsl:value-of select="./td:titre"/></a></li>
</xsl:for-each>
</xsl:for-each>
...
</xsl:template>
<xsl:template match="td:partie">
...
<h2 id="{generate-id(.)}"><xsl:value-of select="./td:titre"/></h2>
...
</xsl:template>