RE: [xsl] Data types and xsl:sequence

Subject: RE: [xsl] Data types and xsl:sequence
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 25 Jan 2005 09:32:25 -0000
If you have two adjacent strings in the sequence used to construct an
element node, a space will be inserted between them. So if you do this:

<a>
  <xsl:sequence select="'aaa'"/>
  <xsl:sequence select="'bbb'"/>
</a>

the result will be 

<a>aaa bbb</a>

There are various ways you can avoid this effect, for example:

<a>
  <xsl:sequence select="concat('aaa','bbb')"/>
</a>

<a>
  <xsl:value-of separator="">
    <xsl:sequence select="'aaa'"/>
    <xsl:sequence select="'bbb'"/>
  </xsl:value-of>
</a>

<a>
  <xsl:value-of select="'aaa'"/>
  <xsl:value-of select="'bbb'"/>
</a>

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Jim Neff [mailto:jneff@xxxxxxxxxxxxxxx] 
> Sent: 24 January 2005 21:18
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Data types and xsl:sequence
> 
> Greetings,
> 
> I'm having trouble understanding data types and using the function
> xsl:sequence.
> 
> I have one common template that I call to create padding in my output
> document:
> 
> <xsl:template name="pad-number">
> 		
>    <xsl:param name="max" />
>    <xsl:param name="char" />
> 
>    <xsl:sequence select="string-join((for $i in 1 to 
> xs:integer($max) return
> $char), '')"/>
> 		
> </xsl:template>
> 
> 
> So if I am padding for a text field, I pass in &#x20; for a 
> space and if
> it's a numeric field I use '0'.
> 
> My problem is (and I know this sounds silly) whenever I 
> change from a text
> to a numeric field there is an extra space inserted into the 
> xsl:sequence
> output.  This is a space and not the character I am passing into this
> template.  So, if I use a tilda '~' instead of '&#x20;' I see the
> appropriate number of tildas plus a space (hex code 20) in my output.
> 
> I do not have this problem when I am not changing from 
> numeric to text, or
> if I have consecutive numerics or consecutive text fields.
> 
> Perhaps I am not using the $max variable correctly?  I found 
> the only way to
> get it to work is when I specify xs:integer around it because 
> the portion of
> code that calls this template is performing a calculation and 
> I think the
> processor (Saxon 8.something) is creating a mandotory 
> xs:double whenever a
> calculation is performed.
> 
> This is probably a logic problem and has nothing to do with 
> XSLT syntax but
> I just thought I'd throw this out here and maybe one of the 
> gurus on this
> list could point me in the right direction.
> 
> Thanks,
> Jim Neff

Current Thread