Bonjour,
J'ai un fichier xml, validé par un schéma. Dans ce fichier certains attributs sont optionnels et ont dans ce cas une valeur par défaut (définie dans le schéma).
Ma question est la suivante : est-il possible dans la transformation xslt de récupérer la valeur par défaut?
Merci d'avance
Le fichier xml :
monschema.xsd :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="matransformation.xslt"?> <catalog xmlns="http://toto.fr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://toto.fr/schema monschema.xsd" xmlns:to="http://toto.fr"> <cd> <title>Empire Burlesque</title> </cd> <cd to:quality="bad"> <title>Greatest Hits</title> </cd> </catalog>
matransformation.xsd:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://toto.fr" xmlns="http://toto.fr"> <xs:element name="cd"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string"/> </xs:sequence> <xs:attribute ref="quality" default="good" /> </xs:complexType> </xs:element> <xs:element name="catalog"> <xs:complexType> <xs:sequence> <xs:element ref="cd" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:attribute name="quality" type="xs:string"> </xs:attribute> </xs:schema>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://toto.fr/schema monschema.xsd" xmlns:to="http://toto.fr"> <xsl:template match="/"> <html> <body> <table border="1"> <xsl:for-each select="child::*"> <xsl:apply-templates/> </xsl:for-each> </table> </body> </html> </xsl:template> <xsl:template match="*"> <tr> <xsl:for-each select="child::*"> <td> <xsl:value-of select="."/> </td> </xsl:for-each> <td> <xsl:value-of select="attribute::to:quality"/> </td> </tr> </xsl:template> </xsl:stylesheet>
Partager