admin管理员组文章数量:1414908
Am trying to split the xml file in to multiple xml files based on the xml tag / in the input xml file. the individual output xml files should go in sequence as per the input xml /from top to bottom of the input xml, xml tag is have unique id.
All the output individual xml files should be in sequence as per the input xml file.
If the input xml doesnt have root element then the xslt code should ignore input xml file, we don't want the empty xml file.
when we execute the xslt code should generate multiple xml files, its have to split the input xml file in to multiple xml files/individual xml files in runtime not to write to any folder.
input xml:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SHIPMENT xmlns:ns0=";>
<events>
<id>1739821652558</id>
<carrier>UPSN</carrier>
</events>
<events>
<id>4239821652567</id>
<carrier>Fedex</carrier>
</events>
<events>
<id>6239828652573</id>
<carrier>USPS</carrier>
</events>
</ns0:MT_SHIPMENT>
when we run the xslt code the output should be Mulitple xml files/individual xml files separate xml files in runtime: Expected output individual files as below:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SHIPMENT xmlns:ns0=";>
<events>
<id>1739821652558</id>
<carrier>UPSN</carrier>
</events>
</ns0:MT_SHIPMENT>
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SHIPMENT xmlns:ns0=";>
<events>
<id>4239821652567</id>
<carrier>USPS</carrier>
</events>
</ns0:MT_SHIPMENT>
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SHIPMENT xmlns:ns0=";>
<events>
<id>6239828652573</id>
<carrier>USPS</carrier>
</events>
</ns0:MT_SHIPMENT>
xsltcode:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl=";>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/root">
<xsl:for-each select="/events/*">
<xsl:result-document method="xml">
<root>
<xsl:copy-of select="/root/@*" />
<elem>
<xsl:copy-of select="../@* | ." />
</elem>
</root>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Am not getting expected output with xml tags and individual/separate xml's.
1739821652558
UPSN
4239821652567
Fedex
6239828652573
USPS
please help us with correct xslt code.
Thanks Ravi
Am trying to split the xml file in to multiple xml files based on the xml tag / in the input xml file. the individual output xml files should go in sequence as per the input xml /from top to bottom of the input xml, xml tag is have unique id.
All the output individual xml files should be in sequence as per the input xml file.
If the input xml doesnt have root element then the xslt code should ignore input xml file, we don't want the empty xml file.
when we execute the xslt code should generate multiple xml files, its have to split the input xml file in to multiple xml files/individual xml files in runtime not to write to any folder.
input xml:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SHIPMENT xmlns:ns0="http://dtc/Shipment">
<events>
<id>1739821652558</id>
<carrier>UPSN</carrier>
</events>
<events>
<id>4239821652567</id>
<carrier>Fedex</carrier>
</events>
<events>
<id>6239828652573</id>
<carrier>USPS</carrier>
</events>
</ns0:MT_SHIPMENT>
when we run the xslt code the output should be Mulitple xml files/individual xml files separate xml files in runtime: Expected output individual files as below:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SHIPMENT xmlns:ns0="http://dtc/Shipment">
<events>
<id>1739821652558</id>
<carrier>UPSN</carrier>
</events>
</ns0:MT_SHIPMENT>
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SHIPMENT xmlns:ns0="http://dtc/Shipment">
<events>
<id>4239821652567</id>
<carrier>USPS</carrier>
</events>
</ns0:MT_SHIPMENT>
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SHIPMENT xmlns:ns0="http://dtc/Shipment">
<events>
<id>6239828652573</id>
<carrier>USPS</carrier>
</events>
</ns0:MT_SHIPMENT>
xsltcode:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3./1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/root">
<xsl:for-each select="/events/*">
<xsl:result-document method="xml">
<root>
<xsl:copy-of select="/root/@*" />
<elem>
<xsl:copy-of select="../@* | ." />
</elem>
</root>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Am not getting expected output with xml tags and individual/separate xml's.
1739821652558
UPSN
4239821652567
Fedex
6239828652573
USPS
please help us with correct xslt code.
Thanks Ravi
Share Improve this question asked Feb 21 at 3:20 ravitejaraviteja 217 bronze badges1 Answer
Reset to default 3Your template matches /root
but the root element of your input XML is ns0:MT_SHIPMENT
. As a result the entire input is processed by the built-in templates.
To get the result you show you would need to do something like:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3./1999/XSL/Transform"
xmlns:ns0="http://dtc/Shipment">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/ns0:MT_SHIPMENT">
<xsl:for-each select="events">
<xsl:result-document href="{id}.xml">
<ns0:MT_SHIPMENT>
<xsl:copy-of select="."/>
</ns0:MT_SHIPMENT>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
本文标签:
版权声明:本文标题:xslt code to split the xml file in to mulitple xml files in runtime based on xml tag <events> and <id&g 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745168654a2645838.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论