|
Subject:
|
Normalize-space() not working
|
|
Posted By:
|
AForgue
|
Post Date:
|
12/5/2003 9:26:53 AM
|
I am having some issues with the normalize-space() function - basically, extra whitespace is not being trimmed.
Input XML:
<text:p text:style-name="Text body">
<text:span text:style-name="T1">Agency problem </text:span>A situation in ...</text:p>
XSLT Template:
<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
|
|
Reply By:
|
armmarti
|
Reply Date:
|
12/5/2003 10:38:27 AM
|
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
|
|
Reply By:
|
AForgue
|
Reply Date:
|
12/5/2003 10:53:22 AM
|
This is the output xml from the transformation (Notice the two spaces after "Agency problem"):
<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
|
|
Reply By:
|
armmarti
|
Reply Date:
|
12/5/2003 11:30:24 AM
|
I'm applying this stylesheet:
<?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:
<?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:
<?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
|
|
Reply By:
|
AForgue
|
Reply Date:
|
12/5/2003 11:39:21 AM
|
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!
|