XSLT到IDoc-XML到纯文本文件
问题描述:
最近我有一个需求,我需要将Idoc-xml转换为纯文本.txt文件并传输到外部合作伙伴。我不熟悉这个XSLT编程,所以任何示例或链接都会非常有帮助。XSLT到IDoc-XML到纯文本文件
我的XML是这样的:
<info>
\t <Segment1>
\t \t <Segment2>
\t \t \t <Segment3>
\t \t \t \t <PO>876522</PO>
\t \t \t </Segment3>
\t \t \t <Segment4>
\t \t \t \t <Date>20171224</Date>
\t \t \t </Segment4>
\t \t \t <Segment5>
\t \t \t \t <Invoice>312</Invoice>
\t \t \t </Segment5>
\t \t </Segment2>
\t </Segment1>
\t <Segment6>
\t \t <Segment7>
\t \t \t <Material>435-A90</Material>
\t \t \t <Quatity>7</Quatity>
\t \t \t <Price>12.00</Price>
\t \t \t <Expiry>01.12.2020</Expiry>
\t \t \t <Item>780AD09</Item>
\t \t \t <Descp>Pencil-56AP</Descp>
\t \t </Segment7>
\t </Segment6>
\t <Segment6>
\t \t <Segment7>
\t \t \t <Material>901-K78</Material>
\t \t \t <Quatity>7</Quatity>
\t \t \t <Price>12.00</Price>
\t \t \t <Expiry>25.01.2028</Expiry>
\t \t \t <Item>90KL76Y</Item>
\t \t \t <Descp>Rubber-90AP</Descp>
\t \t </Segment7>
\t </Segment6>
\t <Segment6>
\t \t <Segment7>
\t \t \t <Material>123-65D</Material>
\t \t \t <Quatity>10</Quatity>
\t \t \t <Price>67.00</Price>
\t \t \t <Expiry>01.01.2020</Expiry>
\t \t \t <Item>LOERF90</Item>
\t \t \t <Descp>Pen-19EU</Descp>
\t \t </Segment7>
\t </Segment6>
</info>
我的预期输出:
876522|24.12.2017|312|435-A90|7|12.00|01.12.2020|780AD09|Pencil-56AP
876522|24.12.2017|312|901-K78|7|12.00|25.01.2028|90KL76Y|Rubber-90AP
876522|24.12.2017|312|123-65D|10|67.00|01.01.2020|LOERF90|Pen-19EU
我需要在项目级循环这是“第6部分”。 非常感谢。
答
试试这个
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="text"></xsl:output>
<xsl:template match="/">
<xsl:for-each select="//Segment6">
<xsl:if test="position() != 1"><xsl:text>
</xsl:text></xsl:if>
<xsl:value-of select="//Segment3/PO"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="//Segment4/replace(Date, '([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])', '$3.$2.$1')"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="//Segment5/Invoice|Segment7/*" separator="|"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
从那里你把欧盟或AP在最后
,是我的错,它只是错字错误。感谢指出。 – Rupesh
对不起Rupesh – RICKYMY