2010-12-06 14 views
0

Hallo Ich versuche, eine XML-Datei von FpML 4 bis FpML 5.XML-Ersatz mit XSL

Das einzige, was ich ändern muss zu konvertieren ist der FpML Header Hier folgt ein Beispiel:

Eingabedatei FpML 4

 <FpML version="4-0" xsi:type="DataDocument" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.fpml.org/2003/FpML-4-0 ../fpml-main-4-0.xsd" xmlns="http://www.fpml.org/2003/FpML-4-0"> 
      <trade>...</trade> 
      <party id="partyA">...</party> 
      <party id="partyB">...</party> 
    </FpML> 

Nun sollte die resultierende Datei wie folgt aussehen:

 <dataDocument xmlns="http://www.fpml.org/FpML-5/confirmation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" fpmlVersion="5-0" xsi:schemaLocation="http://www.fpml.org/FpML-5/confirmation ../../fpml-main-5-0.xsd"> 
      <trade>...</trade> 
      <party id="partyA">...</party> 
      <party id="partyB">...</party> 
    </dataDocument> 

habe ich mit XSL Tutorials probiert und nichts hat wirklich geholfen. Irgendwelche Ideen wären willkommen.

@Update:

Vorerst nur um zu sehen, dass es funktioniert habe ich versucht, diese XSL

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="node() | @*"> 
    <xsl:copy> 
    <xsl:apply-templates select="@* | node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="FpML"> 
    <xsl:element name="test"> 
    <xsl:apply-templates/> 
    </xsl:element> 
</xsl:template> 

Dank

+0

Was haben Sie mit XSL versuchen? Was waren die Fehler? –

+0

@Dave Jarvis: Weil ich XSL dafür verwenden muss. Und kein Fehler ist einfach nicht in der Lage, das XML irgendwie zu transformieren. – inglor

+0

Zeigen Sie uns das von Ihnen verwendete XSL. –

Antwort

2

Dieses Sheet:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fpml4="http://www.fpml.org/2003/FpML-4-0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://www.fpml.org/FpML-5/confirmation" 
exclude-result-prefixes="fpml4"> 
    <xsl:template match="node()|@*"> 
     <xsl:copy> 
      <xsl:apply-templates select="node()|@*"/> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="fpml4:FpML"> 
     <dataDocument fpmlVersion="5-0" 
         xsi:schemaLocation= 
     "http://www.fpml.org/FpML-5/confirmation ../../fpml-main-5-0.xsd"> 
      <xsl:apply-templates select="node()"/> 
     </dataDocument> 
    </xsl:template> 
    <xsl:template match="fpml4:*"> 
     <xsl:element name="{local-name()}"> 
      <xsl:apply-templates select="node()|@*"/> 
     </xsl:element> 
    </xsl:template> 
</xsl:stylesheet> 

Ausgang:

<dataDocument fpmlVersion="5-0" 
xsi:schemaLocation="http://www.fpml.org/FpML-5/confirmation ../../fpml-main-5-0.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://www.fpml.org/FpML-5/confirmation"> 
    <trade>...</trade> 
    <party id="partyA">...</party> 
    <party id="partyB">...</party> 
</dataDocument> 

bearbeiten: Besser mit einem Standard-Namespace ...

+0

Ok gut funktioniert schön. Ich hatte auch die Idee über Namensräume, aber keine Ahnung, wie man sie benutzt. Danke – inglor

+0

@ingor: Sie sind willkommen. Fragen Sie jederzeit. –

1

Hier ist ein Beispiel Sheet, das die Änderung des Eingangs tut Probe, die Sie gefragt haben:

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:fpml4="http://www.fpml.org/2003/FpML-4-0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://www.fpml.org/FpML-5/confirmation" 
    exclude-result-prefixes="fpml4" 
    version="1.0"> 

    <xsl:template match="fpml4:*"> 
    <xsl:element name="{name()}"> 
     <xsl:apply-templates select="@* | node()"/> 
    </xsl:element> 
    </xsl:template> 

    <xsl:template match="fpml4:FpML"> 
    <dataDocument fpmlVersion="5-0" xsi:schemaLocation="http://www.fpml.org/FpML-5/confirmation ../../fpml-main-5-0.xsd"> 
     <xsl:apply-templates/> 
    </dataDocument> 
    </xsl:template> 

    <xsl:template match="@* | text() | comment() | processing-instruction()"> 
    <xsl:copy/> 
    </xsl:template> 

</xsl:stylesheet> 

Ob solch eine einfache Transformation ausreicht, um das Schema zu erfüllen, habe ich überhaupt nicht überprüft.

+0

Das funktioniert auch. Danke. – inglor