Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Adding fixed whitespace to XSLT text output? >Thread Next - Re: Adding fixed whitespace to XSLT text output? Re: Adding fixed whitespace to XSLT text output?To: NULL Date: 3/10/2005 10:49:00 PM I shall assume your template <xsl:template name="runStrPad"> is working fine.. Except you are having some trouble setting variables.. From your XSLT, it seems you have XML something like this.. <root> <foo></foo> <myElement></myElement> <myElement></myElement> ..... </root> Probably you need to write your XSLT as .. <xsl:template match="/root"> <xsl:for-each select="myElement"> <xsl:variable name="padFoo"> <xsl:call-template name="runStrPad"> <xsl:with-param name="string" select="."/> <xsl:with-param name="length" select="16"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="$padFoo"/> </xsl:for-each> </xsl:template> <xsl:template name="runStrPad"> ....... </xsl:template> If you can post your XML and the desired output, I can probably suggest something accurate.. Regards, Mukul "jhouk" wrote: > Thanks! This looks great. I've tried doing a simpler version of this, > but the problem I'm running into is that I need to use the variable > within a "xsl:for-each" loop, so I can't use the absolute method you > use in your xsl:call-template name="str-pad" parameters above. Below > is some code showing the trouble I'm running into. Sorry to be dense, > but can you help me figure out how to set the variables properly? > > Thanks so much! > > <?xml version="1.0"?> > > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:output method="text" /> > > <xsl:variable name="whitespace" select="' '"/> > > <xsl:template match="/root"> > > <xsl:variable name="padFoo"> > <xsl:call-template name="runStrPad"> > <xsl:with-param name="string" select="foo"/> > <xsl:with-param name="length" select="16"/> > </xsl:call-template> > </xsl:variable> > > <xsl:for-each select="myElement"><xsl:value-of > select="$padFoo"/></xsl:for-each> > </xsl:template> > > <xsl:template name="runStrPad"> > <xsl:param name="string"/> > <xsl:param name="length"/> > (runStrPad params: <xsl:value-of select="$string"/>,<xsl:value-of > select="$length"/>) > <xsl:value-of select="concat($string, substring($whitespace, 1, > $length - string-length($string)))"/> > </xsl:template> > > </xsl:stylesheet> > > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
