From: Verachten Bruno (Bruno.Verachten@atosorigin.com)
Date: 01/09/2003 - 16:15
Bonjour,
>Soit le xml suivant :
>*********************
><PARTIE>
> <TITRE>Titre 1</TITRE>
> blah1...blah1...blah1...
> <TITRE>Titre 2</TITRE>
> blah2...blah2...blah2...
> <TITRE>Titre 3</TITRE>
> blah3...blah3...blah3...
></PARTIE>
>
>Je voudrais le transformer via une xslt en :
>********************************************
><PARTIE>
> <TITRE>Titre 1</TITRE>
> <ARTICLE>blah1...blah1...blah1...</ARTICLE>
> <TITRE>Titre 2</TITRE>
> <ARTICLE>blah2...blah2...blah2...</ARTICLE>
> <TITRE>Titre 3</TITRE>
> <ARTICLE>blah3...blah3...blah3...</ARTICLE>
></PARTIE>
Une solution vite faite mal faite :
$ xsltproc.exe test.xsl test.xml
<?xml version="1.0"?>
<PARTIE>
<TITRE>Titre 1</TITRE>
<ARTICLE>blah1...blah1...blah1...</ARTICLE>
<TITRE>Titre 2</TITRE>
<ARTICLE>blah2...blah2...blah2...</ARTICLE>
<TITRE>Titre 3</TITRE>
<ARTICLE>blah3...blah3...blah3...</ARTICLE>
</PARTIE>
=>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="PARTIE">
<xsl:copy>
<xsl:apply-templates select="TITRE|text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="TITRE">
<xsl:copy>
<xsl:value-of select="text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="PARTIE/text()">
<xsl:if test="string-length(normalize-space(.)) > 0">
<ARTICLE><xsl:value-of select="normalize-space(.)"/></ARTICLE>
</xsl:if>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
Bruno Verachten
--
Devenez redacteur <XML>fr et contribuez au developpement du
xml francophone (http://xmlfr.org/infos/redacteurs/) !
Liste de diffusion "xml-tech@xmlfr.org" (http://xmlfr.org).
Cette liste est a votre disposition pour discuter en francais de
tout sujet technique lie a XML.
Pour resilier votre abonnement, envoyez un message contenant
la commande "unsubscribe" a xml-tech-request@xmlfr.org
(mailto:xml-tech-request@xmlfr.org?Subject=unsubscribe)
Archive générée par hypermail 2.1.3 le 28/06/2004 - 11:06 UTC
webmaster@xmlfr.org
|