XML-Austausch mit XSL
Frage
Hallo Ich versuche, eine XML-Datei von FpML 4 bis 5 FpML zu konvertieren.
Das einzige, was ich ändern muß, ist der FpML Kopf 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>
Ich habe versucht, mit XSL-Tutorials um und nichts hat wirklich geholfen. Alle Ideen jemand wäre willkommen.
@Update:
Für jetzt 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>
Danke
Lösung
This stylesheet:
<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>
Output:
<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>
Edit: Better with a default namespace...
Andere Tipps
Here is a sample stylesheet that does the change of the input sample you asked for:
<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>
Whether such a simple transformation is sufficient to satisfy the schema I have not checked at all.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow