Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Adding fixed whitespace to XSLT text output?

From: MukulGandhi@-----------.---------.---
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>
> 
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent