Re: "Remonter" dans un fichier XML

Eric van der Vlist <[email protected]>
Newsgroups gmane.text.xml.french.tech
Organization Dyomedea (http://dyomedea.com)
Message-ID <[email protected]>
Bonjour,
Le mercredi 15 février 2006 à 14:22 +0100, [email protected] a
écrit :
> Bonjour,
> 
> J'ai un fichier XML de la sorte
> 
> <liste>
> 	<theme id="Spécial : Alex Mucchielli">
> 		<fichier>articles/article_dynamique.xml</fichier>
> 		<fichier>articles/article_articulation.xml</fichier>
> 	</theme>
> </liste>
> 
> Afin de lister les articles je fais :
> 
> <xsl:template match="liste">
> 
> <xsl:apply-templates select="document(theme//fichier)/ARTICLE">
> <xsl:sort select="." order="descendant"/>
> </xsl:apply-templates>
> 
> </xsl:template>
> 
> <xsl:template match="ARTICLE">
> 
> <p><b><xsl:value-of select="id" /></b> - <i><xsl:value-of
> select="id/@auteur" /></i>
> <br/>Theme : <xsl:value-of select="$fichier_nom" /></p>
> <p><xsl:value-of select="resume" /></p>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> Le probleme c'est que je souhaiterais remonter dans le fichier XML pour
> afficher le theme mais aussi le nom du fichier a coté de chaques titres.
> 
> J'ai bien peur que ca soit impossible... Je me trompe ?

Oui ;-) ...

Pour cela, il faut "mémoriser" dans une variable ou un paramètre
l'information que vous allez perdre en changeant de document.

Il y a plusieurs manières de faire, par exemple :

<!-- On applique les règles sur l'élément fichier, qui est dans le
document d'origine. -->

<xsl:template match="liste">

<xsl:apply-templates select="theme/fichier">
  <xsl:sort select="document(.)/ARTICLE" order="descendant"/>
</xsl:apply-templates>

</xsl:template>

<<!-- On défini une règle sur l'élément fichier -->

<xsl:template match="fichier">

<xsl:apply-templates select="document(.)/ARTICLE">
  <xsl:with-param name="theme" select="../@id">
</xsl:apply-templates>

</xsl:template>

<!-- On utilise ce paramètre -->

<xsl:template match="ARTICLE">
<xsl:param name="theme"/>

<p><b><xsl:value-of select="id" /></b> - <i><xsl:value-of
select="id/@auteur" /></i>
<br/>Theme : <xsl:value-of select="$theme" /></p>
<p><xsl:value-of select="resume" /></p>
</xsl:template>

</xsl:stylesheet>

(Non testé et pouvant donc contenir des erreurs de frappe)

Cordialement,

Eric van der Vlist

-- 
GPG-PGP: 2A528005
Lisez-moi sur XMLfr.
                       http://xmlfr.org/index/person/eric+van+der+vlist/
------------------------------------------------------------------------
Eric van der Vlist       http://xmlfr.org            http://dyomedea.com
(ISO) RELAX NG   ISBN:0-596-00421-4 http://oreilly.com/catalog/relax
(W3C) XML Schema ISBN:0-596-00252-1 http://oreilly.com/catalog/xmlschema
------------------------------------------------------------------------


-- Attached file included as plaintext by Ecartis --

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBD8y3pDvn+ZCpSgAURAtKGAKCNDb2Zz0vuTYtf1495t1fRzNLmNwCfap6n
r8GVK/ADhaoVSMWboVlTe0U=
=/bzD
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.