fonction document() (Mise à jour d'un document xml à partir d'un autre)
Salut tout le monde,
Afin de compléter un document xml (source.xml) à partir d'un autre xml (manquants.xml) j'utilise la fonction document()
Voici un exemple:
source.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <?xml version="1.0" encoding="UTF-8"?>
<liste>
<rub titre="A">
<spe titre="Ab"/>
<spe titre="Abw"/>
<spe titre="Abz"/>
</rub>
<rub titre="B">
<spe titre="Ba"/>
<spe titre="Bc"/>
</rub>
</liste> |
manquants.xml
Code:
1 2 3 4 5
| <?xml version="1.0" encoding="UTF-8"?>
<manquant>
<spe titre="Aa"/>
<spe titre="Bb"/>
</manquant> |
Une fois compléter dans l'ordre de tri voici le résultat souhaité
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?xml version="1.0" encoding="UTF-8"?>
<liste>
<rub titre="A">
<spe titre="Aa"/>
<spe titre="Ab"/>
<spe titre="Abw"/>
<spe titre="Abz"/>
</rub>
<rub titre="B">
<spe titre="Ba"/>
<spe titre="Bb"/>
<spe titre="Bc"/>
</rub>
</liste> |
j'ai commencé à écrire cette xslt
A titre d'exemple:
Code:
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
| <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:template match="/">
<xsl:apply-templates select="liste"/>
</xsl:template >
<!--pour copier tout le contenu de source.xml-->
<xsl:template match="*|text()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="spe">
<xsl:for-each select="document('manquant.xml')//spe">
<xsl:variable name="ajout" select="@titre"/>
<xsl:choose>
<xsl:when test="$ajout < current()/@titre">
<spe>
<xsl:attribute name="titre">
<xsl:value-of select="current()/@titre"/>
</xsl:attribute>
</spe>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="titre">
<xsl:value-of select="$ajout"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet> |
merci pour votre aide
Merci pour votre aide