Probléme et optimisation XSLT
Bonjour à tous,
Voila je viens a vous car j'ai un souci concernant l’écriture d'une feuille xslt.
J'ai un fichier xml contenant les données que je dois formater selon un format bien précis et produire un fichier texte.
Voila un extrait du fichier de donnée:
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 34 35 36 37 38 39 40
|
<cim:Plant rdf:about="____centraleproduction_2">
<Plant.sInstTotale>0.0</Plant.sInstTotale>
<Plant.sRaccB>0.0</Plant.sRaccB>
<Plant.qRacc>0.0</Plant.qRacc>
<Plant.type>photovoltaique</Plant.type>
<cim:PowerSystemResource.Location rdf:resource="____siteproduction_2"/>
<cim:EquipmentContainer.Equipments rdf:resource="____protectiondecouplage_2"/>
<Plant.stockage>true</Plant.stockage>
<Plant.sRaccC>0.0</Plant.sRaccC>
<Plant.sRacc>0.0</Plant.sRacc>
<cim:EquipmentContainer.Equipments rdf:resource="____batteriecondensateurs_2"/>
<Plant.pRacc>0.0</Plant.pRacc>
<Plant.qMin>0.0</Plant.qMin>
<cim:IdentifiedObject.name>CENTRALE PV</cim:IdentifiedObject.name>
<Plant.qMax>0.0</Plant.qMax>
<Plant.raccordement>triphase</Plant.raccordement>
<Plant.pInstTotale>0.0</Plant.pInstTotale>
<Plant.sRaccA>0.0</Plant.sRaccA>
<cim:EquipmentContainer.Equipments rdf:resource="____troncon_2"/>
<Plant.eProduiteMoyAnnuelle>0.0</Plant.eProduiteMoyAnnuelle>
<Plant.Season rdf:resource="____saison"/>
<cim:IdentifiedObject.mRID>__centraleproduction_2</cim:IdentifiedObject.mRID>
</cim:Plant>
<cim:ACLineSegment rdf:about="____troncon_2">
<cim:PowerSystemResource.AssetDataSheet rdf:resource="____modeletroncon"/>
<ACLineSegment.type>raccordement</ACLineSegment.type>
<cim:ACLineSegment.x>0.2</cim:ACLineSegment.x>
<cim:ACLineSegment.r>0.1</cim:ACLineSegment.r>
<cim:IdentifiedObject.aliasName/>
<cim:IdentifiedObject.name/>
<cim:IdentifiedObject.mRID>__troncon_2</cim:IdentifiedObject.mRID>
</cim:ACLineSegment>
<cim:Switch rdf:about="____protectiondecouplage_2">
<cim:PowerSystemResource.AssetDataSheet rdf:resource="____modeleprotectiondecouplage"/>
<cim:IdentifiedObject.mRID>__protectiondecouplage_2</cim:IdentifiedObject.mRID>
</cim:Switch> |
Chaques balises (Switch, Plant, ACLineSegment) représentent des objets ainsi que leurs attributs après génération depuis un modèle UML.
Il peut exister une relation entre l'objet Plant et/ou ACLinSegment,Switch par le biais de l'attribut "cim:EquipmentContainer.Equipments" de l’élément Plant.
Dans mon fichier texte final, je dois afficher certaines infos de l’élément Plant et dire si par exemple il est relié avec un switch :
L’élément <cim:EquipmentContainer.Equipments rdf:resource="____protectiondecouplage_2"/> trouve une correspondance avec l'element <cim:Switch rdf:about="____protectiondecouplage_2"> en effet l'attribut rdf:resource match parfaitement avec l'attribut rdf:about (____troncon_2 = ____troncon_2) !
J'ai fait une moulinette qui permet de faire ça mais c'est vraiment de la bidouille, j'aimerai savoir s'il existe un moyen plus propre de faire ça ?
Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
<xsl:template match="cim:Plant">
<!--Pour chaque Equipment de Plant, on verifie si c'est une protection de découplage-->
<xsl:variable name="organeCoupureTest">
<xsl:for-each select="cim:EquipmentContainer.Equipments">
<xsl:variable name="ressource" select="@rdf:resource"/>
<xsl:for-each select="//cim:Switch">
<xsl:if test="$ressource = @rdf:about">1</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="origProd" select="0"/>
<xsl:variable name="organeCoupure" select="if ($organeCoupureTest = '1') then 'Prod' else 'Noeud' "/>
<xsl:variable name="sPuissanceNom" select="if (Plant.sRacc[node()]) then Plant.sRacc else '-' "/>
<xsl:variable name="puissanceActive" select="if (Plant.sRacc[node()]) then Plant.sRacc else '-' "/>
<xsl:variable name="puissanceReactiveMax" select="if (Plant.qMax[node()]) then Plant.qMax else '-' "/>
<xsl:variable name="puissanceReactiveMin" select="if (Plant.qMin[node()]) then Plant.qMin else '-' "/>
<xsl:variable name="puissanceReactiveProd" select="if (Plant.qRacc[node()]) then Plant.qRacc else '-' "/>
<xsl:value-of select="concat($id,$SautDeLigne,$organeCoupure,$virg,$origProd,$virg,$sPuissanceNom,$virg,$puissanceActive,$virg,$puissanceReactiveMax,$virg,$puissanceReactiveMin,$virg,$puissanceReactiveProd,$SautDeLigne)"/>
</xsl:template> |
Le for-each imbriqué ne me plait pas du tout et puis le fait de mettre la variable à 1 quand une correspondance est trouvée puis de tester cette variable pour afficher la bonne string dans le fichier texte c'est pas top !
Voila si quelqu'un peut m'aider à optimiser ça je lui en serai reconnaissant !
Merci à vous