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 December 5th, 2003, 10:26 AM
Authorized User
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Normalize-space() not working

I am having some issues with the normalize-space() function - basically, extra whitespace is not being trimmed.

Input XML:
Code:
<text:p text:style-name="Text body">
   <text:span text:style-name="T1">Agency problem  </text:span>A situation in ...</text:p>
XSLT Template:
Code:
<xsl:template match="text:p">
   <glossaryterm>
      <term><xsl:value-of select="normalize-space(child::text:span/text())"/></term>
      <definition><xsl:value-of select="text()"/></definition>
   </glossaryterm>
</xsl:template>
If I replace normalize-space(child::text:span/text()) with normalize-space(' foobar ') the extra space is trimmed correctly. Any ideas on what I am doing wrong?

Thanks in advance for any help!
Aaron
 
Old December 5th, 2003, 11:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

The function normalize-space() removes starting and trailing whitespace and replaces all other whitespace characters by single whitespace. And also the function takes as an argument a string(if not specified, the context node's string value is taken). Your code must work properly I think, it's quite ok. What do you get as a result?

Regards,
Armen
 
Old December 5th, 2003, 11:53 AM
Authorized User
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the output xml from the transformation (Notice the two spaces after "Agency problem"):

Code:
<glossaryterm>
   <term>Agency problem  </term>
   <definition>A situation in which a firms’ top managers (i.e., the “agents” of the firms’ owners) do not act in the best interests of the shareholders.</definition>
</glossaryterm>
Aaron
 
Old December 5th, 2003, 12:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

I'm applying this stylesheet:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:text="aaa">
    <xsl:template match="text:p">
   <glossaryterm>
      <term><xsl:value-of select="normalize-space(child::text:span/text())"/></term>
      <definition><xsl:value-of select="text()"/></definition>
   </glossaryterm>
</xsl:template>    
</xsl:stylesheet>
to the XML doc:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<text:p text:style-name="Text body" xmlns:text="aaa">
   <text:span text:style-name="T1">Agency problem  </text:span>A situation in ...</text:p>
and getting this output:

Code:
<?xml version="1.0" encoding="utf-8"?><glossaryterm xmlns:text="aaa"><term>Agency problem</term><definition>
   </definition></glossaryterm>
I'm using Saxon 6.5.2. May be your XSLT processor is doing messy things?

Regards,
Armen
 
Old December 5th, 2003, 12:39 PM
Authorized User
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using Xselerator for development purposes, and when I use the stylesheet in OpenOffice as an XML Export Filter it also produces the incorrect results.

Who knows. I might just need to strip the spaces later on in the process.

Thanks for your help!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using normalize-space() eg. with position() Smirre XSLT 5 November 11th, 2008 12:30 PM
Strangely working XSLT function normalize-space() seetaramayya XSLT 2 April 23rd, 2007 06:26 AM
space is not working.. gantait XSLT 5 February 26th, 2007 04:39 AM
normalize-space() gantait XSLT 0 February 26th, 2007 03:29 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM





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