Pour reformuler le pb, je cherche à créer un attribut id pour chaque noeud
à partir du xsl, ce id commençant à 2 et s'incrémentant au fil des noeuds.
Je remets en PJ les fichiers de travail que j'ai un peu modifié pour qu'il
correspondent plus à ce que je veux.
Le format de l'attribut id="Id_x" du xml output est imposé.
Dans le xsl beaucoup de commentaire qui sont des essais de différentes
méthodes que j'ai trouvé sur le net ou dans les bouquins et que j'ai
essayé d'implémenter sans succès. Peut être que cela donnera des idées.
Merci et à bientôt
Bernols
Les fichiers:
SAPinput.xml
<?xml version="1.0" encoding="UTF-16"?>
<SAP xsi:noNamespaceSchemaLocation="SAP.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ficheInformation>
<fiche>
<NomDuDocument>sap</NomDuDocument>
<TypeDuDocument>Fichier de données</TypeDuDocument>
<DateDeCreation>2006-01-30</DateDeCreation>
</fiche>
<fiche>
<NomDuDocument>sop</NomDuDocument>
<TypeDuDocument>Fichier de texte</TypeDuDocument>
<DateDeCreation>2006-01-30</DateDeCreation>
</fiche>
</ficheInformation>
</SAP>
SAP.xsl
<?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"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<!--modification de encoding-->
<xsl:output method="xml" encoding="ISO-8859-1" indent="yes"/>
<!--DOCTYPE D [
<!ELEMENT ID (customer-id)>
<!ELEMENT customer-id (#PCDATA)>]
-->
<!--xsl:key name="IDs" match="ficheInformation/*" use="Id_"/-->
<!--xsl:for-each
select="//ficheInformation[generate-id(.)=generate-id(key('IDs',
Id_)[1])]">
</xsl:for-each-->
<xsl:template match="/SAP">
<ModeleExport>
<!--xsl:attribute
name="xsi:noNamespaceSchemaLocation">ModeleExport.xsd</xsl:attribute-->
<!--sélection de ficheInformation-->
<xsl:apply-templates select="ficheInformation"/>
</ModeleExport>
<!--/xsl:template>
<xsl:template name="tRec">
<xsl:param name="x"/>
<xsl:if test="x < 10">
<xsl:call-template name="tRec">
<xsl:with-param name="x" select="$x + 1"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="x >= 10">
<xsl:value-of select="$x"/>
</xsl:if-->
</xsl:template>
<!--conception de l'élément ficheInformation-->
<xsl:template match="ficheInformation">
<!--xsl:for-each
select="//ficheInformation[generate-id(.)=generate-id(key('IDs',
Id_)[1])]">
</xsl:for-each-->
<ficheInformation id="{concat('Id_',position()+1)}">
<!--xsl:attribute name="{concat('a',position())}"></xsl:attribute-->
<!--xsl:attribute name="id"-->
<!--xsl:call-template name="tRec"-->
<!--xsl:with-param name="x" select="2"/-->
<!--/xsl:call-template-->
<!--xsl:value-of select="@id"/-->
<!--/xsl:attribute-->
<!--xsl:for-each select="//ficheInformation"-->
<xsl:for-each select="fiche">
<!--fiche
id="{concat('Id_',position()+number(ficheInformation/@id1))}"-->
<fiche id="{concat('Id_',position()+'@id')}">
<!--xsl:attribute name="id"><xsl:value-of
select="@id"/></xsl:attribute-->
<NomDuDocument>
<xsl:value-of select="NomDuDocument"/>
</NomDuDocument>
<TypeDuDocument>ModeleExport</TypeDuDocument>
<DateDeCreation>
<xsl:value-of select="DateDeCreation"/>
</DateDeCreation>
<InformationUsager>
<xsl:value-of select="InformationUsager"/>
</InformationUsager>
<!--xsl:attribute name="id">
<xsl:value-of
select="id={concat('Id_',//ficheInformation[position()])}"></xsl:value-of>
</xsl:attribute-->
</fiche>
</xsl:for-each>
</ficheInformation>
</xsl:template>
</xsl:stylesheet>
XML à obtenir : SAPoutputModele.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<ModeleExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ficheInformation id="Id_2">
<fiche id="Id_3">
<NomDuDocument>sap</NomDuDocument>
<TypeDuDocument>ModeleExport</TypeDuDocument>
<DateDeCreation>2006-01-30</DateDeCreation>
<InformationUsager></InformationUsager>
</fiche>
<fiche id="Id_4">
<NomDuDocument>sop</NomDuDocument>
<TypeDuDocument>ModeleExport</TypeDuDocument>
<DateDeCreation>2006-01-30</DateDeCreation>
<InformationUsager></InformationUsager>
</fiche>
</ficheInformation>
</ModeleExport>
--
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)
Received on Tue Apr 4 21:51:37 2006