[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Converting XML to Fixed Length Text Data

Subject: Re: Converting XML to Fixed Length Text Data
From: "Garvin Franco" <garvin_franco@xxxxxxxxxxx>
Date: Tue, 26 Mar 2002 20:29:02 -0500
xsl fixed length
David, I tried using the template you showed me, but I got output such as


instead of the positions specified in Problem below

1) Can you provide full details for at least one element and one attribute?

2) What happens if one of the elements is optional and not passed on the source xml file? Wouldn't this throw off the position of the fields which follow? ( e.g. if child2 was not on the source xml file, what impact would this have on the output? )

<<<< Solution >>>>>>>>>>

Solution: ( David's response )
<xsl:variable name="pad1" select="'       '"/>

<xsl:template match="child1">
<xsl:value-of select="."/>
<xsl:value-of select="substring($child1,string-length(.))"/>

and similarly the other children. (This doesn't do any error checking
for over-run, although that could be added.)


<<<<<Problem >>>>>>>>>>>>>
Ladies and Gents, I need some guidance .  I searched the archives and found
some info but it was not sufficient. Basically I want to convert an xml file
to a fixed length data file.  The following is a sample of what I am trying
to do

Position of data for output file:
field: child1     start 1    length 7
field: att1       start 12   length 5
field: child2     start 27   length 12
field: child3     start 39   length 15
field: att2       start 56   length 3

<parent att1="foo">
<child3 att2="bar">yetAnotherChild</child3>

aChild     foo            anotherChildyetAnotherChild  bar

Thanking you in advance for the info

Garvin Franco

From: David Carlisle <davidc@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Converting XML to Fixed Length Text Data
Date: Mon, 25 Mar 2002 21:28:28 GMT

  David thanks for the response, but I am not quite clear on the solution.
  1) How does the attribute "att1" vs the element "child1" know where to
  position themselves on the output file? Shouldn't positional info be
  declared somewhere?
it is "declared" by the length of the string variable declared for each
field. If $child2 starts off as a string of 20 spaces and
you do
<xsl:value-of select="."/>
<xsl:value-of select="substring($child2,string-length(.))"/>
in the template for child2, then you will get the character data
of the element followed by enough spaces to pad the total to 20
characters (as long as the element had less than 20 characters)

2) What about the element <xsl:text>, is this not required? xsl:text is in favt never required, but here you don't need it as you are not adding any literal text, only some spaces, which you can enter with xsl:value-of.

So apart from the template I showed, you just need the settings of the
original strings to give the widths of each field, plus the template for
teh parent element needs to give a line break after each row, which you
can do with xsl:text (<xsl:text>
</xsl:text>) or value-of
(<xsl:value-of select="'


This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list

Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.