在SAP中将XML文件转换为固定长度的平面文件
这是EDIfact发票。尝试使用脚本,它可以帮助-
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" encoding="ISO-8859-1"/> <xsl:template match="/"> <!-- EDI_DC40 --> <xsl:for-each select="IDataXMLCoder/record/idatacodable/array/idatacodable/record/value"> <xsl:value-of select="text()"/> <xsl:choose> <!-- TABNAM (10) --> <xsl:when test="@name = 'TABNAM'"> <xsl:choose> <xsl:when test="string-length(text()) = 0"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 1"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 2"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 3"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 4"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 5"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 6"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 7"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 8"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 9"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) > 10"> <xsl:message terminate="yes">ERROR: The maximum length of "TABNAM" is 10 characters.</xsl:message> </xsl:when> <xsl:otherwise/> </xsl:choose> </xsl:when> <!-- MANDT (3)--> <xsl:when test="MANDT"> <xsl:choose> <xsl:when test="string-length(text()) = 0"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 1"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 2"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) > 3"> <xsl:message terminate="yes">ERROR: The maximum length of "MANDT" is 3 characters.</xsl:message> </xsl:when> <xsl:otherwise/> </xsl:choose> </xsl:when> <!-- DOCNUM (16) --> <!-- DOCREL (4) --> <!-- STATUS (4) --> <!-- etc. --> </xsl:choose> </xsl:for-each> <xsl:text>
</xsl:text> <!-- E1EDK01 --> <xsl:for-each select="IDataXMLCoder/record/idatacodable/array/idatacodable/array/idatacodable/record/value"> <xsl:value-of select="text()"/> <xsl:choose> <!-- ACTION (3) --> <xsl:when test="@name = 'ACTION'"> <xsl:choose> <xsl:when test="string-length(text()) = 0"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 1"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) = 2"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) > 3"> <xsl:message terminate="yes">ERROR: The maximum length of "ACTION" is 3 characters.</xsl:message> </xsl:when> <xsl:otherwise/> </xsl:choose> </xsl:when> <!-- KZABS (1)--> <xsl:when test="KZABS"> <xsl:choose> <xsl:when test="string-length(text()) = 0"> <xsl:text></xsl:text> </xsl:when> <xsl:when test="string-length(text()) > 1"> <xsl:message terminate="yes">ERROR: The maximum length of "KZABS" is 1 character.</xsl:message> </xsl:when> <xsl:otherwise/> </xsl:choose> </xsl:when> <!-- CURCY (3) --> <!-- HWAER (3) --> <!-- WKURS (12) --> <!-- etc. --> </xsl:choose> </xsl:for-each> </xsl:template> </xsl:stylesheet>
有许多站点提供了内置脚本,可将EDIfact转换为XSLT。检查这个网站,它可能也有帮助-
https://www.codeproject.com/Articles/11278/EDIFACT-to-XML-to-Anything-You-Want