Key - multiples documents XML
Bonjour, je vous présente mon problème :
j'ai un fichier avec des id et des labels associés :
state_solos.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
<?xml version="1.0"?>
<!-- key_state.xml -->
<Procedure>
<StateType Id="MAT.REC" aName="description 1"/>
<StateType Id="MAT.ETU" aName="description 2"/>
<StateType Id="MAT.DOS" aName="description 3"/>
<StateType Id="OUT.REC" aName="description 4"/>
<StateType Id="OUT.MON" aName="description 5"/>
<StateType Id="OUT.CAB" aName="description 6"/>
<StateType Id="OUT.ADA" aName="description 7"/>
<StateType Id="OUT.TES" aName="description 8"/>
<StateType Id="ROB.UTI" aName="description 9"/>
<StateType Id="PHA.INS" aName="description 10"/>
</Procedure> |
un fichier contenant un rapport avec des activités qui ont pluiseurs états
one_activity.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
<?xml version="1.0" encoding="ASCII"?>
<air:Report xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:air="http://www.scopp.org/air" xmlns:b2mml="http://www.wbf.org/xml/b2mml" xmlns:extensions="http://www.wbf.org/xml/b2mml-extensions" xmlns:scada="http://www.scopp.org/scada" ContactCustomer="M. Doe" Customer="Mr Client" Description="description lambda" RefCustom="T5E8ZA" RefERP="PPP105682" State="EDITED">
<air:Session>
<air:Activity BeginDate="2011-01-24T09:32:30.831+01:00" EndDate="2011-01-24T09:43:37.355+01:00">
<air:Type>FER.OUT.SOL</air:Type>
<air:State>
<air:State>
<air:Type>MAT.REC</air:Type>
<air:Value>UNDEFINED</air:Value>
</air:State>
<air:State>
<air:Type>OUT.MON</air:Type>
<air:Value>FALSE</air:Value>
</air:State>
</air:State>
<air:Event Date="2011-01-24T09:43:37.355+01:00" Description="">
<air:Type>BAGUE.AUTRE</air:Type>
</air:Event>
</air:Activity>
</air:Session>
</air:Report> |
enfin le fichicer xsl de transformation
simple_mapping.xsl
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
|
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:air="http://www.scopp.org/air" >
<xsl:output method="text"/>
<!-- Assign contents of key_state.xml to var -->
<xsl:variable name="ProceduresLookup" select="document('state_solos.xml')"/>
<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>
<!-- Define key -->
<xsl:key name="procedureKey" match="//Procedure/StateType" use="@Id"/>
<!-- Plug in key value -->
<xsl:template match="//air:Type">
<!--<xsl:variable name="type" select="substring-after(.,'#')"/>-->
<xsl:variable name="type" select="."/>
<xsl:for-each select="$ProceduresLookup">
<xsl:value-of select="$type"/> correspond a <xsl:value-of select="key('procedureKey', $type)"/> ++++++++
<xsl:value-of select="$newline"/>
<xsl:text>. </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet> |
l'idée est de charger les états avec l'instruction key et de générer une sortie pour laquelle les id de types d'état sont remplacés par leur description aName.
Mon soucis est que les id de statetype ne sont pas trouvés.
Par exemple, je devrais obtenir
OUT.MON correspond a description 5
Je n'arrive pas a savoir si ca vient du tableau associatif qui serait vide, d'ailleurs comment inspecter son contenu avec xmlspy.
Ou peut-etre du fait que type à l'air de valoir par exemple UNDEFINEDOUT.MON, UNDEFINED provient de la valeur du air:Type précédent.
La technique provient de l'article suivant http://www.vckbase.com/vckbase/ebook...html/x14-2.htm dont l'exemple produit bien le résultat escompté.
Merci de toute proposition, idée, support moral ou autre :mouarf: