[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: How to pad space to a text node to make it have specfic
Albert - In the second 'with-param' in the calls, change 'parVar' to 'padVar'. Also, in the append-pad call, I don't think that you can pass the same parameter in twice. (I didn't check the spec, but I believe it uses the last parameter of the same name that you use and ignores all previous.) List - Are there any smart editors out there with completion and error checking so misspellings like this would be much easier to spot? Also, is there any reason why it'd be beneficial to allow parameters to be passed into a template that didn't exist in the template's 'xsl:param' definitions? Gotta be missing something, Nate -----Original Message----- From: Albert Tsun [mailto:albert.tsun@xxxxxxxxxxxx] Sent: Sunday, October 22, 2000 10:36 PM To: xsl-list@xxxxxxxxxxxxxxxx; naustin@xxxxxxxxxxxxxxx Subject: RE: How to pad space to a text node to make it have specfic lengt h? Hi Nate, XML data source: <SetReport1:Qty>1000</SetReport1:Qty> <SetReport1:Price>1000.00</SetReport1:Price> XSL stylesheet Problems: (1) <xsl:call-template name="prepend-pad"> <xsl:with-param name="padChar"> </xsl:with-param> <xsl:with-param name="parVar" select="SetReport1:Qty"/> <xsl:with-param name="length" select="15"/> </xsl:call-template> - It does not show what I expected (" 1000") instead irt show blanks. Any mistake I make on above scripts (2) <xsl:call-template name="append-pad"> <xsl:with-param name="padChar"> </xsl:with-param> <xsl:with-param name="parVar" select='format-number(SetReport1:Price,"###,###,###,##0","SetReportDF")'/> <xsl:with-param name="parVar" select="SetReport1:Qty"/> <xsl:with-param name="length" select="15"/> </xsl:call-template> - It does not show what I expected (" 1,000.00") instead irt show blanks. Any mistake I make on above scripts Please help and advice. Many Thanks in advance. Albert Excel Technology Int. (HK) Ltd Nate Austin <naustin@xxxxxxxxxxxxxxx> on 10/18/2000 11:48:55 PM Please respond to xsl-list@xxxxxxxxxxxxxxxx To: "'xsl-list@xxxxxxxxxxxxxxxx'" <xsl-list@xxxxxxxxxxxxxxxx> cc: (bcc: Albert Tsun/Excel) Subject: RE: How to pad space to a text node to make it have specfic lengt h? Albert - These are the templates I use to pad on the left or right with any character passed in: <xsl:template name="prepend-pad"> <!-- recursive template to right justify and prepend--> <!-- the value with whatever padChar is passed in --> <xsl:param name="padChar"> </xsl:param> <xsl:param name="padVar"/> <xsl:param name="length"/> <xsl:choose> <xsl:when test="string-length($padVar) < $length"> <xsl:call-template name="prepend-pad"> <xsl:with-param name="padChar" select="$padChar"/> <xsl:with-param name="padVar" select="concat($padChar,$padVar)"/> <xsl:with-param name="length" select="$length"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="substring($padVar,string-length($padVar) - $length + 1)"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="append-pad"> <!-- recursive template to left justify and append --> <!-- the value with whatever padChar is passed in --> <xsl:param name="padChar"> </xsl:param> <xsl:param name="padVar"/> <xsl:param name="length"/> <xsl:choose> <xsl:when test="string-length($padVar) < $length"> <xsl:call-template name="append-pad"> <xsl:with-param name="padChar" select="$padChar"/> <xsl:with-param name="padVar" select="concat($padVar,$padChar)"/> <xsl:with-param name="length" select="$length"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="substring($padVar,1,$length)"/> </xsl:otherwise> </xsl:choose> </xsl:template> The 'padChar' param passed in could be as many characters as you want, actually. 'padVar' is the variable to pad, and length is length, obviously. Most of the XSLT I do is for fixed-length text files, and these haven't failed me yet. Hope this helps, Nate >Date: Wed, 18 Oct 2000 16:46:26 +0800 >From: "Albert Tsun" <albert.tsun@xxxxxxxxxxxx> >Subject: How to pad space to a text node to make it have specfic length? > >Hi all, > >I am trying hard to pad space to a text node so that the data value >will have a specific length. > >XML Source : ><records> > <record> > <field1>abc</field1> > <field2>abcdef</field2> > </record> > <record> > <field1>123</field1> > <field2>12345</field2> > </record> ></records> > >My current task is to transform it to a fixed length record files which >look like >abc | abcdef| >123 | 12345| > > >I want to pass the <field1> to template "padleft" with field1 text node and >desired length >and <field2> to "padright" in order to make a fixed length output. However, >with all the >String functions in XSLT, I can't figure out how I can implement this. >would some help me >and give me some sample code, please. >XSL : ><xsl:template name="padleft"> > <xsl:param name="src"/> > <xsl:param name="len"/> > > <.????? How to pad spaces to $src to make it a $len longed text >????????> > > ></xsl:template> > >Many Thanks in advance XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|