CV
Un schéma de CV
Soit le schéma XML suivant (formalisme DTD) :
1
<!ELEMENT cv (nom, prenom, age?, rubrique+)>
2
<!ELEMENT nom (#PCDATA)>
3
<!ELEMENT prenom (#PCDATA)>
4
<!ELEMENT age (#PCDATA)>
5
<!ELEMENT rubrique (titre, contenu)>
6
<!ELEMENT contenu (#PCDATA)>
7
<!ELEMENT titre (#PCDATA)>
Question
Écrire un document XML valide par rapport à ce schéma avec au moins un élément age et deux rubriques.
Indice
1
<cv>
2
<nom>...</nom>
3
...
4
<rubrique>
5
...
6
</rubrique>
7
<rubrique>
8
...
9
</rubrique>
10
</cv>
Solution
1
<cv>
2
<nom>Brassens</nom>
3
<prenom>Georges</prenom>
4
<age>33</age>
5
<rubrique>
6
<titre>Compétences</titre>
7
<contenu>Chanteur, auteur, compositeur, guitariste</contenu>
8
</rubrique>
9
<rubrique>
10
<titre>Langues étrangères</titre>
11
<contenu>Espagnol, lu, parlé, chanté</contenu>
12
</rubrique>
13
</cv>
Question
Écrire un document HTML cible d'une transformation XSLT de ce document.
Les nom, prénom et age seront en italique, les titres de rubriques seront en gras.
Indice
1
<html>
2
<head>
3
<title>...</title>
4
</head>
5
<body>
6
<p><i>...</i></p>
7
<p><i>...</i></p>
8
<p><i>...</i></p>
9
<p><b>...</b></p>
10
<p>...</p>
11
...
12
</body>
13
</html>
Solution
1
<html>
2
<head>
3
<title>CV de Georges Brassens</title>
4
</head>
5
<body>
6
<p><i>Georges</i></p>
7
<p><i>Brassens</i></p>
8
<p><i>33 ans</i></p>
9
<p><b>Compétences</b></p>
10
<p>Chanteur, auteur, compositeur, guitariste</p>
11
<p><b>Langues étrangères</b></p>
12
<p>Espagnol, lu, parlé, chanté</p>
13
</body>
14
</html>
Question
Écrire le programme de transformation XSLT d'un fichier XML en fichier HTML.
Indice
1
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
<xsl:template match="cv">
4
<html>
5
<head>
6
<title>CV de <xsl:value-of select="..."/> <xsl:value-of select="..."/> </title>
7
</head>
8
<body>
9
<xsl:apply-templates/>
10
</body>
11
</html>
12
</xsl:template>
13
<xsl:template match="nom">
14
<p><i>...</i></p>
15
</xsl:template>
16
...
17
<xsl:template match="rubrique">
18
...
19
</xsl:template>
20
<xsl:template match="titre">
21
...
22
</xsl:template>
23
...
24
</xsl:stylesheet>
Solution
1
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
4
<xsl:template match="cv">
5
<html>
6
<head>
7
<title>CV de <xsl:value-of select="nom"/>
8
<xsl:value-of select="prenom"/>
9
</title>
10
</head>
11
<body>
12
<xsl:apply-templates/>
13
</body>
14
</html>
15
</xsl:template>
16
17
<xsl:template match="nom">
18
<p><i><xsl:value-of select="."/></i></p>
19
</xsl:template>
20
21
<xsl:template match="prenom">
22
<p><i><xsl:value-of select="."/></i></p>
23
</xsl:template>
24
25
<xsl:template match="age">
26
<p><i><xsl:value-of select="."/> ans</i></p>
27
</xsl:template>
28
29
<xsl:template match="rubrique">
30
<xsl:apply-templates/>
31
</xsl:template>
32
33
<xsl:template match="titre">
34
<p><b><xsl:value-of select="."/></b></p>
35
</xsl:template>
36
37
<xsl:template match="contenu">
38
<p><xsl:value-of select="."/></p>
39
</xsl:template>
40
41
</xsl:stylesheet>