XML 删除命名空间前缀
XML remove Namespace prefix
我有这个 XML :
<mes:Fichier xmlns:mes="http://file.message.fr">
<mes:toto>XXXXX</mes:toto>
<yyy:Document xmlns:yyy="urn:iso:std:iso:20022:tech:xsd:acmt.02y.001.01:Forward">
<yyy:id>1<yyy:id>
</yyy:Document>
<yyy:Document xmlns:yyy="urn:iso:std:iso:20022:tech:xsd:acmt.02y.001.01:Forward">
<yyy:id>2<yyy:id>
</yyy:Document>
</mes:Fichier>
我想为每个文档标签拆分这个:
以我为例:
文件 1 :
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:acmt.02y.001.01:Forward">
<id>1<id>
</Document>
文件 2:
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:acmt.02y.001.01:Forward">
<id>2<id>
</Document>
我已经实现了这个 xsl,但我不知道如何删除输出文件中的所有名称空间前缀并使用参数设置 href。
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="//*[contains(local-name(), 'Document')]">
<xsl:result-document href="file{position()}.xml">
<xsl:copy-of select="current()"/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我想删除输出文件中的所有命名空间前缀。
我该怎么做?
谢谢
i dont know how to remove all namespaces prefixe in the output files ...
尝试:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:for-each select="//*[contains(local-name(), 'Document')]">
<xsl:result-document href="file{position()}.xml">
<xsl:apply-templates select="."/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
... and set the href with a parameter.
要使用名为 FILENAME
的参数而不是字符串 "file",请将其添加到样式表的顶层:
<xsl:param name="FILENAME">
并更改:
<xsl:result-document href="file{position()}.xml">
至:
<xsl:result-document href="{$FILENAME}{position()}.xml">
我有这个 XML :
<mes:Fichier xmlns:mes="http://file.message.fr">
<mes:toto>XXXXX</mes:toto>
<yyy:Document xmlns:yyy="urn:iso:std:iso:20022:tech:xsd:acmt.02y.001.01:Forward">
<yyy:id>1<yyy:id>
</yyy:Document>
<yyy:Document xmlns:yyy="urn:iso:std:iso:20022:tech:xsd:acmt.02y.001.01:Forward">
<yyy:id>2<yyy:id>
</yyy:Document>
</mes:Fichier>
我想为每个文档标签拆分这个: 以我为例:
文件 1 :
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:acmt.02y.001.01:Forward">
<id>1<id>
</Document>
文件 2:
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:acmt.02y.001.01:Forward">
<id>2<id>
</Document>
我已经实现了这个 xsl,但我不知道如何删除输出文件中的所有名称空间前缀并使用参数设置 href。
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="//*[contains(local-name(), 'Document')]">
<xsl:result-document href="file{position()}.xml">
<xsl:copy-of select="current()"/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我想删除输出文件中的所有命名空间前缀。 我该怎么做?
谢谢
i dont know how to remove all namespaces prefixe in the output files ...
尝试:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:for-each select="//*[contains(local-name(), 'Document')]">
<xsl:result-document href="file{position()}.xml">
<xsl:apply-templates select="."/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
... and set the href with a parameter.
要使用名为 FILENAME
的参数而不是字符串 "file",请将其添加到样式表的顶层:
<xsl:param name="FILENAME">
并更改:
<xsl:result-document href="file{position()}.xml">
至:
<xsl:result-document href="{$FILENAME}{position()}.xml">