I am working with a client who uses 'Workday' ERP. This ERP mainly deals with XML, XSLT and XSD scripting but not other programming languages to transform the data in and out of the ERP.
I have a fixed-length text file (sample Below) that I am trying to convert it to XML for further processing in my code. I have always used XSLT to convert xml to xml (OR) xml to text but not vice versa.
Can you please guide me or provide a sample XSLT (2.0 or 3.0) to convert the below text data into target XML (below).
Input Fixed Length File: (First Character is record Type, X, H are headers, the last T, F are trailers. Each Employee record starts with 1 E record, followed by multiple W records and B records (Optional)).
X T3.03Q2020320201029015631AACW2 xxxxxxx 2020xx 090420
H ZXCV 20200930 ABCABCA ABCABC
E ******13662 372022456 Tony B StarkS 99999 Heritage Pkwy zzzzzz MI48092 YNNNMS19960706 19720724 PM 99999 Heritage Pkwy zzzzzz MI48092
WW_SWW26 61322 1524206 1442835 1442835 0 0 0 0 0 0 215611 5342667 5073153 5073153 0 0 0 NN 0 0 N N 0000000000YYY 14 440 0 0 0 0 0 0N
WW_CITYR2665440 9192 972143 919215 919215 0 0 0 0 0 0 9192 972143 919215 919215 0 0 0 NN 0 0 N N 0000000000NYY 14 440 0 0 0 0 0 0N
BW_OASFEDERAL 93217 1524206 1503506 1503506 0 0 0 0 0 0 327181 5342667 5277117 5277117 0 0 0 NN 0 0 N N 0000000000YYY 14 440 0 0 0 0 0 0N
E ******10665 362022493 Thor S Asar 2323 Clyde Road Highzzzz MI48357 YNNNMS19990517 19760301 PM 2323 Clyde Road Highzzzz MI48357
WW_SWW26 61322 1524206 1442835 1442835 0 0 0 0 0 0 215611 5342667 5073153 5073153 0 0 0 NN 0 0 N N 0000000000YYY 14 440 0 0 0 0 0 0N
WW_CITYR2665440 9192 972143 919215 919215 0 0 0 0 0 0 9192 972143 919215 919215 0 0 0 NN 0 0 N N 0000000000NYY 14 440 0 0 0 0 0 0N
BW_OASFEDERAL 93217 1524206 1503506 1503506 0 0 0 0 0 0 327181 5342667 5277117 5277117 0 0 0 NN 0 0 N N 0000000000YYY 14 440 0 0 0 0 0 0N
BW_OASFEDERAL 93217 1524206 1503506 1503506 0 0 0 0 0 0 327181 5342667 5277117 5277117 0 0 0 NN 0 0 N N 0000000000YYY 14 440 0 0 0 0 0 0N
T 39384 1699589934
F 43442 1854024842
The expected XMl output is something like below:
<?xml version='1.0' encoding='utf-8'?>
<File>
<X_Header></X_Header>
<H_Header></H_Header>
<All_Employees>
<Employee>
<E_record></E_record>
<W_record></W_record>
<W_record></W_record>
<W_record></W_record>
<B_record></B_record>
</Employee>
<Employee>
<E_record></E_record>
<W_record></W_record>
<W_record></W_record>
<W_record></W_record>
<B_record></B_record>
</Employee>
</All_Employees>
<T_Trailer></T_Trailer>
<F_Trailer></F_Trailer>
</File>
unparsed-textXPath 2 function to read in a text file into a string, in XSLT 3 you additionally haveunparsed-text-linesas a function to read in a text file in a sequence of strings representing the lines. You usually start processing in that case with a named template (e.g.<xsl:template name="main">...</xsl:template>in XSLT 2 or in XSLT 3 with the predefined<xsl:template name="xsl:initial-template">...</xsl:template>. To further break up strings use thetokenizefunction and/or theanalyze-stringfunction or thexsl:analyze-stringinstruction.