在 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
广告