[XML]Trasformazione XSLT. Puntare ad un ben preciso nodo?

Linguaggi di programmazione: php, perl, python, C, bash, ecc.

[XML]Trasformazione XSLT. Puntare ad un ben preciso nodo?

Messaggioda harpefalcata » giovedì 18 maggio 2017, 12:24

Buongiorno a tutti.

Ho uno strano problema con un file XML, che devo trasformare in un secondo file XML, diverso dal primo, tramite una trasformazione XSLT.

Questo è il file XML di partenza:

Codice: Seleziona tutto
<EMIRReporting AuthorityKey="" CreationDateAndTime="" Version="1.0">
<ExchangeCollateralReportInfo>
<ExchangeCollateralRecord>
<RequestType>A</RequestType>
<NotificationIdentifier>46</NotificationIdentifier>
<ApplicantCounterparty>
<ApplicantCounterpartyIdentifier>
<ApplicantCounterpartyLEIIdentifier>
<ApplicantCounterpartyIdentifierLEIType>LEI</ApplicantCounterpartyIdentifierLEIType>
<ApplicantCounterpartyIdentifierLEIValue>DMJYFTBC4387RTNCAEKJ</ApplicantCounterpartyIdentifierLEIValue>
</ApplicantCounterpartyLEIIdentifier>
</ApplicantCounterpartyIdentifier>
<ApplicantCounterpartyName>Denominazione 1</ApplicantCounterpartyName>
<ApplicantCounterpartyStatus>FC   </ApplicantCounterpartyStatus>
<ApplicantCounterpartyCountry>IT</ApplicantCounterpartyCountry>
<ApplicantCounterpartyCompetentAuthority>CONSOB</ApplicantCounterpartyCompetentAuthority>
</ApplicantCounterparty>
<IntragroupCounterparty>
<IntragroupCounterpartyIdentifier>
<IntragroupCounterpartyLEIIdentifier>
<IntragroupCounterpartyIdentifierLEIType>LEI</IntragroupCounterpartyIdentifierLEIType>
<IntragroupCounterpartyIdentifierLEIValue>DMJYFTBC4387RTNCAEKJ</IntragroupCounterpartyIdentifierLEIValue>
</IntragroupCounterpartyLEIIdentifier>
</IntragroupCounterpartyIdentifier>
<IntragroupCounterpartyName>Denominazione 2</IntragroupCounterpartyName>
<IntragroupCounterpartyStatus>FC</IntragroupCounterpartyStatus>
<IntragroupCounterpartyCountry>RU</IntragroupCounterpartyCountry>
</IntragroupCounterparty>
<CorporateRelationship>
<CorporateRelationshipType>AFF </CorporateRelationshipType>
<CorporateRelationshipEvidenceList>
<CorporateRelationshipEvidenceDocument>
<Path>.</Path>
<FileSequenceNumber>000001</FileSequenceNumber>
</CorporateRelationshipEvidenceDocument>
</CorporateRelationshipEvidenceList>
</CorporateRelationship>
<CategoryOfIGT>3</CategoryOfIGT>
<ListOfIGTAssetClass>
<IGTAssetClass>
<IGTAssetClassValue>CO</IGTAssetClassValue>
<ListOfIGTTypes>
<IGTType>Forwards, Swaps</IGTType>
</ListOfIGTTypes>
<ListOfIGTNotionalCurrency>
<IGTNotionalCurrency>IRR, ISK, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW, KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LTL, LVL, LYD, MAD, MDL, MGA, MKD, MMK, MNT</IGTNotionalCurrency>
</ListOfIGTNotionalCurrency>
<ListOfIGTSettlementCurrency>
<IGTSettlementCurrency>BZD, CAD, CDF, CHF, CLP, CNY, COP, COU, CRC, CUP, CVE, CYP, CZK, DJF, DKK, DOP, DZD, EEK, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JMD</IGTSettlementCurrency>
</ListOfIGTSettlementCurrency>
<IGTTenor>33</IGTTenor>
<IGTSettlementType>P</IGTSettlementType>
<IGTFrequency>123</IGTFrequency>
<IGTVolume>45.000</IGTVolume>
<IGTSize>345.000</IGTSize>
</IGTAssetClass>
<IGTAssetClass>
<IGTAssetClassValue>CR</IGTAssetClassValue>
<ListOfIGTTypes>
<IGTType>Swaps, Options</IGTType>
</ListOfIGTTypes>
<ListOfIGTNotionalCurrency>
<IGTNotionalCurrency>LAK, LBP, LKR, LRD, LSL, LTL, LVL, LYD, MAD, MDL, MGA, MKD, MMK, MNT, MOP, MRO, MTL, MUR, MVR, MWK, MXN, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD</IGTNotionalCurrency>
</ListOfIGTNotionalCurrency>
<ListOfIGTSettlementCurrency>
<IGTSettlementCurrency>CRC, CUP, CVE, CYP, CZK, DJF, DKK, DOP, DZD, EEK, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW, KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LTL</IGTSettlementCurrency>
</ListOfIGTSettlementCurrency>
<IGTTenor>30</IGTTenor>
<IGTSettlementType>B</IGTSettlementType>
<IGTFrequency>32</IGTFrequency>
<IGTVolume>465.000</IGTVolume>
<IGTSize>634.000</IGTSize>
</IGTAssetClass>
<IGTAssetClass>
<IGTAssetClassValue>CU</IGTAssetClassValue>
<ListOfIGTTypes>
<IGTType>Options, Others</IGTType>
</ListOfIGTTypes>
<ListOfIGTNotionalCurrency>
<IGTNotionalCurrency>ERN, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW, KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL</IGTNotionalCurrency>
</ListOfIGTNotionalCurrency>
<ListOfIGTSettlementCurrency>
<IGTSettlementCurrency>GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW, KRW, KWD, KYD, KZT</IGTSettlementCurrency>
</ListOfIGTSettlementCurrency>
<IGTTenor>22</IGTTenor>
<IGTSettlementType>C</IGTSettlementType>
<IGTFrequency>2</IGTFrequency>
<IGTVolume>456.000</IGTVolume>
<IGTSize>345.000</IGTSize>
</IGTAssetClass>
<IGTAssetClass>
<IGTAssetClassValue>EQ</IGTAssetClassValue>
<ListOfIGTTypes>
<IGTType>Forwards, Options</IGTType>
</ListOfIGTTypes>
<ListOfIGTNotionalCurrency>
<IGTNotionalCurrency>HKD, HNL, HRK, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW, KRW, KWD, KYD, KZT, LAK, LBP, LKR, LRD, LSL, LTL, LVL, LYD, MAD</IGTNotionalCurrency>
</ListOfIGTNotionalCurrency>
<ListOfIGTSettlementCurrency>
<IGTSettlementCurrency>BOB, BRL, BSD, BTN, BWP, BYR, BZD, CAD, CDF, CHF, CLP, CNY, COP, COU, CRC, CUP, CVE, CYP, CZK, DJF, DKK, DOP, DZD, EEK, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JMD, JOD, JPY, KES, KGS, KHR</IGTSettlementCurrency>
</ListOfIGTSettlementCurrency>
<IGTTenor>24</IGTTenor>
<IGTSettlementType>P</IGTSettlementType>
<IGTFrequency>11</IGTFrequency>
<IGTVolume>456.000</IGTVolume>
<IGTSize>654.000</IGTSize>
</IGTAssetClass>
<IGTAssetClass>
<IGTAssetClassValue>IR</IGTAssetClassValue>
<ListOfIGTTypes>
<IGTType>Swaps, Others</IGTType>
</ListOfIGTTypes>
<ListOfIGTNotionalCurrency>
<IGTNotionalCurrency>ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, INR, IQD, IRR, ISK, JMD, JOD, JPY, KES, KGS, KHR</IGTNotionalCurrency>
</ListOfIGTNotionalCurrency>
<ListOfIGTSettlementCurrency>
<IGTSettlementCurrency>MDL, MGA, MKD, MMK, MNT, MOP, MRO, MTL, MUR, MVR, MWK, MXN, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN, PGK, PHP, PKR, PLN, PYG</IGTSettlementCurrency>
</ListOfIGTSettlementCurrency>
<IGTTenor>3</IGTTenor>
<IGTSettlementType>B</IGTSettlementType>
<IGTFrequency>22</IGTFrequency>
<IGTVolume>346.000</IGTVolume>
<IGTSize>453.000</IGTSize>
</IGTAssetClass>
</ListOfIGTAssetClass>
<IGTEvidenceDocumentList>
<IGTEvidenceDocument>
<Code>A</Code>
<Path>.</Path>
<FileSequenceNumber>000002</FileSequenceNumber>
</IGTEvidenceDocument>
<IGTEvidenceDocument>
<Code>B</Code>
<Path>.</Path>
<FileSequenceNumber>000003</FileSequenceNumber>
</IGTEvidenceDocument>
<IGTEvidenceDocument>
<Code>C</Code>
<Path>.</Path>
<FileSequenceNumber>000004</FileSequenceNumber>
</IGTEvidenceDocument>
<IGTEvidenceDocument>
<Code>D</Code>
<Path>.</Path>
<FileSequenceNumber>000005</FileSequenceNumber>
</IGTEvidenceDocument>
</IGTEvidenceDocumentList>
<NotificationDate>2017-05-19</NotificationDate>
<ExchangeCollateralDecision>
<PositiveDecision>
<DecisionDate/>
<DecisionValue>POS</DecisionValue>
<ExemptionState>FU</ExemptionState>
<ReasonForApproval/>
</PositiveDecision>
</ExchangeCollateralDecision>
</ExchangeCollateralRecord>
</ExchangeCollateralReportInfo>
</EMIRReporting>


E questo è il file XSLT che ho elaborato io:

Codice: Seleziona tutto
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method='xml' indent='yes'/>
                     
      <xsl:template match="//IGTNotionalCurrency">
         <xsl:value-of select="."/>
      </xsl:template>      
      
</xsl:stylesheet>   


Il mio problema è questo:

Devo riuscire ad estrarre, e poi manipolare dall'XML di partenza, quella stringa composta dlunghissima che compare sotto il tag IGTNotionalCurrency, e poi dovrò fare lo stesso anche con tutte le altre stringhe, ma per il momento vorrei sapere come farlo con questa.

Il mio xslt però, oltre ad estrarre questa stringa, estrae anche il valore di tutti gli altri campi, e non capisco perchè.

C'è un modo di rendere più selettiva la mia trasformazione xsl?

Inoltre vorrei chiedere: Come faccio a specificare da xsl quale delle cinque possibili "IGTNotionalCurrency" voglio accedere?

Inoltre, come si può vedere questa stringa è composta da una serie di valori separati da una virgola.
E' possibile separare questa stringa composta, magari tramite uno split e creare un nuovo nodo, per ogni possibile valore e distribuirci dentro tutte le possibili scelte?

Grazie mille e buona giornata
Avatar utente
harpefalcata
Scoppiettante Seguace
Scoppiettante Seguace
 
Messaggi: 642
Iscrizione: ottobre 2015
Località: Roma, Italia
Desktop: Unity
Distribuzione: Ubuntu 16.04.2 Xenial Xerus
Sesso: Maschile

Torna a Programmazione

Chi c’è in linea

Visualizzano questa sezione: 0 utenti registrati e 4 ospiti