Re: [xsl] normalize-space and sequence

Subject: Re: [xsl] normalize-space and sequence
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Thu, 27 Sep 2007 11:09:52 +0200
Mathieu Malaterre wrote:
On 9/27/07, Abel Braaksma <abel.online@xxxxxxxxx> wrote:
Maybe I totally misunderstood your question, but if I did, please
respond with a tiny example of what you are after: a small but working
xslt document, a small input and a small output xml document, plus an
extra output xml containing what you want different. You know, with xml
it is like with pictures: one xml says more than a thousand words, but
thousand xmls (or very large ones) say nothing. ;)

Hi Abel,


  Thanks again for your help. I think I have rewritten what happen in
a shorter example:

http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/xslt/ws.xml
and
http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/xslt/ws.xsl

Could you please let me know how to fix the following:

Thanks for the shorter samples, that sure helps a lot. But I still prefer them in the mail, though (link vanish with time).
I don't see how you applied my changes.. This is your stylesheet:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
 <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
 <xsl:template match="@*">
   <xsl:attribute name="{name()}" select="normalize-space(.)"/>
 </xsl:template>
 <xsl:template match="text()">
   <xsl:value-of select="normalize-space(.)"/>
 </xsl:template>
 <xsl:template match="/">
   <xsl:apply-templates select="*"/>
 </xsl:template>
 <xsl:template match="table">
   <table>
     <xsl:apply-templates/>
   </table>
 </xsl:template>
 <xsl:template match="entry/para">
   <entry ie="{.}"/>
 </xsl:template>
</xsl:stylesheet>


I suggested to use a variable, like so:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
 <xsl:output method="xml" indent="yes" encoding="UTF-8"/>

 <!-- whitespace correction templates -->
 <xsl:template match="@*" mode="correct-ws">
   <xsl:attribute name="{name()}" select="normalize-space(.)"/>
 </xsl:template>

 <xsl:template match="text()" mode="correct-ws">
   <xsl:value-of select="normalize-space(.)"/>
 </xsl:template>

 <xsl:template match="/" mode="correct-ws">
   <xsl:variable name="output">
      <xsl:apply-templates select="*"/>
   </xsl:variable>
   <xsl:apply-templates select="$output/*" mode="correct-ws" />
 </xsl:template>

 <!-- normal templates -->
 <xsl:template match="table">
   <table>
     <xsl:apply-templates/>
   </table>
 </xsl:template>

 <xsl:template match="entry/para">
   <entry ie="{.}"/>
 </xsl:template>

</xsl:stylesheet>


That should do it. I didn't test it though ;)


Cheers,
-- Abel Braaksma

Current Thread