CV

Un schéma de CV

Soit le schéma XML suivant (formalisme DTD) :

<!ELEMENT cv (nom, prenom, age?, rubrique+)>
<!ELEMENT nom (#PCDATA)>
<!ELEMENT prenom (#PCDATA)>
<!ELEMENT age (#PCDATA)>
<!ELEMENT rubrique (titre, contenu)>
<!ELEMENT contenu  (#PCDATA)>
<!ELEMENT titre (#PCDATA)>

Écrire un document XML valide par rapport à ce schéma avec au moins un élément age et deux rubriques.

<cv>
  <nom>...</nom>
  ...
  <rubrique>
    ...
  </rubrique>
  <rubrique>
    ...
  </rubrique>
</cv>
<cv>
  <nom>Brassens</nom>
  <prenom>Georges</prenom>
  <age>33</age>
  <rubrique>
    <titre>Compétences</titre>
    <contenu>Chanteur, auteur, compositeur, guitariste</contenu>
  </rubrique>
  <rubrique>
    <titre>Langues étrangères</titre>
    <contenu>Espagnol, lu, parlé, chanté</contenu>
  </rubrique>
</cv>

É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.

<html>
  <head>
    <title>...</title>
  </head>
  <body>
    <p><i>...</i></p>
    <p><i>...</i></p>
    <p><i>...</i></p>
    <p><b>...</b></p>
    <p>...</p>
    ...
  </body>
</html>
<html>
  <head>
    <title>CV de Georges Brassens</title>
  </head>
  <body>
    <p><i>Georges</i></p>
    <p><i>Brassens</i></p>
    <p><i>33 ans</i></p>
    <p><b>Compétences</b></p>
    <p>Chanteur, auteur, compositeur, guitariste</p>
    <p><b>Langues étrangères</b></p>
    <p>Espagnol, lu, parlé, chanté</p>
  </body>
</html>

Écrire le programme de transformation XSLT d'un fichier XML en fichier HTML.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="cv">
  <html>
    <head>
      <title>CV de <xsl:value-of select="..."/ <xsl:value-of select="..."/> </title>
    </head>
    <body>
      <xsl:apply-templates/>
    </body>
  </html>
</xsl:template>
<xsl:template match="nom">
  <p><i>...</i></p>
</xsl:template>
...
<xsl:template match="rubrique">
  ...
</xsl:template>
<xsl:template match="titre">
  ...
</xsl:template>
...
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="cv">
  <html>
    <head>
      <title>CV de <xsl:value-of select="nom"/> <xsl:value-of select="prenom"/> </title>
    </head>
    <body>
      <xsl:apply-templates/>
    </body>
  </html>
</xsl:template>
<xsl:template match="nom">
  <p><i><xsl:value-of select="."/></i></p>
</xsl:template>
<xsl:template match="prenom">
  <p><i><xsl:value-of select="."/></i></p>
</xsl:template>
<xsl:template match="age">
  <p><i><xsl:value-of select="."/> ans</i></p>
</xsl:template>
<xsl:template match="rubrique">
  <xsl:apply-templates/>
</xsl:template>
<xsl:template match="titre">
  <p><b><xsl:value-of select="."/></b></p>
</xsl:template>
<xsl:template match="contenu">
  <p><xsl:value-of select="."/></p>
</xsl:template>
</xsl:stylesheet>
AccueilExercices > Exercices XSLT > Exercice : CV< PrécédentSuivant >