xslt - XML remove Namespace prefix -
i have 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>
i split 1 each document tag : example :
file1 :
<document xmlns="urn:iso:std:iso:20022:tech:xsd:acmt.02y.001.01:forward"> <id>1<id> </document>
file2 :
<document xmlns="urn:iso:std:iso:20022:tech:xsd:acmt.02y.001.01:forward"> <id>2<id> </document>
i have implemented xsl dont know how remove namespaces prefixe in output files , set href parameter.
<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 remove namespaces prefixe in output files. how can ?
thank you
i dont know how remove namespaces prefixe in output files ...
try:
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>
... , set href parameter.
to use parameter named filename
instead of string "file", add top level of stylesheet:
<xsl:param name="filename">
and change:
<xsl:result-document href="file{position()}.xml">
to:
<xsl:result-document href="{$filename}{position()}.xml">
Comments
Post a Comment