题
嗨,我正在尝试将FPML 4的XML文件转换为FPML 5。
我唯一要更改的是fpml标头,以下是一个示例:
输入文件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>
现在结果文件应该看起来像:
<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>
我尝试了XSL教程,但没有任何帮助。任何人都会受到欢迎。
@更新:
现在只是为了看到它正在工作,我尝试了此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>
谢谢
解决方案
此样式表:
<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>
输出:
<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>
编辑: :更好地使用默认名称空间...
其他提示
这是一个示例样式表,可以更改您要求的输入示例:
<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>
如此简单的转换是否足以满足我根本没有检查的模式。
不隶属于 StackOverflow