The secret to doing this in XSLT 1.0 is to realize that you can combine a "padding strategy" with a "substring strategy" to either pad or cut off a piece of text to a desired width. In particular, XSLT instructions of this form:
substring(concat('value to pad or cut', ' '), 1, 5)
...where concat
is used to add a number of padding characters to a string and substring
is used to limit the overall width, are helpful. With that said, here's an XSLT 1.0 solution that accomplishes what you want.
Please note that in your expected output, some of the character widths do not match your requirements; for example, according to the requirements, <LastName>
should be sized to 16 characters, whereas your output appears to cut it off at 13. That said, I believe my solution below outputs what you expect.
When this XSLT:
<?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="no" 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="Detail">
<xsl:apply-templates />
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="SSN">
<xsl:value-of
select="substring(concat(., ' '), 1, 9)"/>
</xsl:template>
<xsl:template match="DOB">
<xsl:value-of
select="substring(concat(translate(., '/', ''), ' '), 1, 8)"/>
</xsl:template>
<xsl:template match="LastName">
<xsl:value-of
select="substring(concat(., ' '), 1, 16)"/>
</xsl:template>
<xsl:template match="FirstName">
<xsl:value-of
select="substring(concat(., ' '), 1, 13)"/>
</xsl:template>
<xsl:template match="Date">
<xsl:value-of
select="substring(concat(translate(., '/', ''), ' '), 1, 8)"/>
</xsl:template>
<xsl:template match="Time">
<xsl:value-of
select="substring(concat(., ' '), 1, 8)"/>
</xsl:template>
<xsl:template match="CurrentStreetAddress1">
<xsl:value-of
select="substring(concat(., ' '), 1, 28)"/>
</xsl:template>
<xsl:template match="CurrentCity">
<xsl:value-of
select="substring(concat(., ' '), 1, 25)"/>
</xsl:template>
<xsl:template match="CurrentStat">
<xsl:value-of
select="substring(concat(., ' '), 1, 15)"/>
</xsl:template>
</xsl:stylesheet>
...is run against the provided XML (with a </Detail>
added to make the document well-formed):
<Report>
<table1>
<Detail_Collection>
<Detail>
<SSN>*********</SSN>
<DOB>1980/11/11</DOB>
<LastName>user</LastName>
<FirstName>test</FirstName>
<Date>2013/02/26</Date>
<Time>14233325</Time>
<CurrentStreetAddress1>53 MAIN STREET</CurrentStreetAddress1>
<CurrentCity>san diego</CurrentCity>
<CurrentState>CA</CurrentState>
</Detail>
</Detail_Collection>
</table1>
</Report>
...the wanted result is produced:
*********19801111user test 201302261423332553 MAIN STREET san diego CA