Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 4th, 2007, 08:11 AM
Authorized User
 
Join Date: Apr 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default string-length problem

HI ,

I have a xsl like this

<Order>
  <xsl:value-of select="string-length(string(/TemplateName/Order))"/>
</Order>

If the value in /TemplateName/Order is "Simple" it is giving 6

If the value in /TemplateName/Order is just empty space it is giving 6

I dont know why it is giving 6 instead of 1.
My input is

<TemplateName>
  <Order> </Order>
</TemplateName>
See Order just contains space .
If i use <xsl:value-of select="string-length(string(/TemplateName/Order))"/>
It is giving 6 as output . I am using xalan processor .Any info on this?


A. Sasi
__________________
A. Sasi
 
Old July 4th, 2007, 08:13 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Very odd, can you show a small reproducible example?

--

Joe (Microsoft MVP - XML)
 
Old July 4th, 2007, 09:25 AM
Authorized User
 
Join Date: Apr 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

MY XSL IS :-

<xsl:stylesheet xmlns:js="javascriptcode" xmlns:java="http://xml.apache.org/xslt/java" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lxslt="http://xml.apache.org/xslt" version="1.0" exclude-result-prefixes=" js java xsl lxslt">
  <xsl:template match="/">
    <xsl:apply-templates select="b"/>
  </xsl:template>
  <xsl:template match="b">
    <c>
      <c1>
        <xsl:value-of select="string-length(string(/b/b1))"/>
      </c1>
    </c>
  </xsl:template>
</xsl:stylesheet>

my xml is :-

<b>
  <b1> </b1>
  <b2>August</b2>
</b>

My Output is :-

<c>
<c1>6</c1>
</c>
actually c1 should contain 1 because b1 contains a single space.i dont know why it is happening ?
For this i am using xalan 2.1 processor.Is it because of the processor or because of xsl.

A. Sasi
 
Old July 4th, 2007, 10:08 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

When I run that with Saxon 8.9 I get the xpected result of 1.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fix string length Ivanchan Excel VBA 2 July 26th, 2007 08:55 AM
Chap 3, "Length of String" richajos BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 February 25th, 2006 08:38 PM
Changing length of string automatically ryanvdm2 Classic ASP Basics 5 September 4th, 2005 06:20 PM
How to obtain String length in twips mike123abc VB How-To 5 December 11th, 2003 01:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.