Here, I have explained one scenario where business is expecting fixed length format file with content of each field are left justified and remaining unused width of each field's are padded with blank spaces to maintain every field's start and end position in a text file output.
I have leveraged the use of a XSLT mapping to achieve this requirement.This XSLT mapping can be leveraged by developers to edit and modify and enhanced according to other business requirements as well.
Field specification are detailed below for the use case shown in this blog post:
<Records>
<Header>
<HeaderIndicator>H</HeaderIndicator>
<HeaderDate>20210405</HeaderDate>
<HeaderFiller> </HeaderFiller>
</Header>
<Detail>
<DetailIndicator>D</DetailIndicator>
<DetailRecordDate>20210405</DetailRecordDate>
<Name>Deepak Jaiswal</Name>
<Phone>123457890</Phone>
</Detail>
<Detail>
<DetailIndicator>D</DetailIndicator>
<DetailRecordDate>20210405</DetailRecordDate>
<Name>Rajesh Sharma</Name>
<Phone>234578901</Phone>
</Detail>
<Detail>
<DetailIndicator>D</DetailIndicator>
<DetailRecordDate>20210405</DetailRecordDate>
<Name>Lokesh Kumar</Name>
<Phone>345789012</Phone>
</Detail>
<Trailer>
<TrailerIndicator>T</TrailerIndicator>
<TrailerDate>20210405</TrailerDate>
<DetailRecordCount>0000000003</DetailRecordCount>
<TrailerFiller> </TrailerFiller>
</Trailer>
</Records>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes" method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Header">
<xsl:apply-templates />
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="HeaderIndicator">
<xsl:value-of
select="substring(concat(., ' '), 1, 1)"/>
</xsl:template>
<xsl:template match="HeaderDate">
<xsl:value-of
select="substring(concat(., ' '), 1, 10)"/>
</xsl:template>
<xsl:template match="HeaderFiller">
<xsl:value-of
select="substring(concat(., ' '), 1, 100)"/>
</xsl:template>
<xsl:template match="Detail">
<xsl:apply-templates />
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="DetailIndicator">
<xsl:value-of
select="substring(concat(., ' '), 1, 1)"/>
</xsl:template>
<xsl:template match="DetailRecordDate">
<xsl:value-of
select="substring(concat(., ' '), 1, 10)"/>
</xsl:template>
<xsl:template match="Name">
<xsl:value-of
select="substring(concat(., ' '), 1, 50)"/>
</xsl:template>
<xsl:template match="Phone">
<xsl:value-of
select="substring(concat(., ' '), 1, 50)"/>
</xsl:template>
<xsl:template match="Trailer">
<xsl:apply-templates />
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="TrailerIndicator">
<xsl:value-of
select="substring(concat(., ' '), 1, 1)"/>
</xsl:template>
<xsl:template match="TrailerDate">
<xsl:value-of
select="substring(concat(., ' '), 1, 10)"/>
</xsl:template>
<xsl:template match="DetailRecordCount">
<xsl:value-of
select="substring(concat(., ' '), 1, 10)"/>
</xsl:template>
<xsl:template match="TrailerFiller">
<xsl:value-of
select="substring(concat(., ' '), 1, 90)"/>
</xsl:template>
</xsl:stylesheet>
Image 4 : Portion of XSLT mapping to maintained correctly as per field length
Final Output Fixed Length text file looks like below:
H20210405
D20210405 Deepak Jaiswal 123457890
D20210405 Rajesh Sharma 234578901
D20210405 Lokesh Kumar 345789012
T20210405 0000000003
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |