Re: [xsl] normalize-space and newlines

Subject: Re: [xsl] normalize-space and newlines
From: david_n_bertoni@xxxxxxxxxx
Date: Wed, 24 Aug 2005 00:32:28 -0400
> Hello
> Moving on from cleaning up yesterday's not-so-difficult-after-all 
"noise" in
> my ex-Framemaker file there are still a couple of things which confuse 
> in particular some persistent newlines.


> The first XSL pass strips out any completely empty nodes, removes the 
> entities and also drops any images within headings (they're purely
> ornamental anyway):


> There are two more things I want to do before translating the content of
> this document into my own structure. Firstly dropping all <A> and 
> <IMAGE> tags has left me with a number of empty <DIV> entities, so pass2
> repeats the pass1 technique to do this. Secondly a lot of the entities 
> contain newlines and/or leading spaces, thanks to Framemaker's choice of
> when to break the lines (usually after an opening tag and before the
> content).
> So this is my second pass stylesheet:


> <!-- fold newlines in text elements to spaces, etc. -->
> <xsl:template match="text()" priority="2">
> <xsl:value-of select="normalize-space(.)"/>
> </xsl:template>

This template has no "mode" attribute, so it's never matched.  This brings 
up the question as to why you are using modes at all, when all of your 
templates have apply-templates instructions that all use the same mode.

> <!-- Drop any empty nodes -->
> <xsl:template match="@*|node()" mode="copy">
> <!-- non-empty: has children, is a text node, has value or attribute -->
> <xsl:if test="node() or * or text() or string(.) or @*">
> <xsl:copy>
> <xsl:copy-of select="@*"/>
> <xsl:apply-templates mode="copy"/>
> </xsl:copy>
> </xsl:if>
> </xsl:template>

The expression of the xsl:if "test" attribute seems strange to me.  Is 
there any reason why you don't have a separate template for element nodes?

<xsl:template match="@*|node()" mode="copy">
<xsl:apply-templates select="@*|node()" mode="copy"/>

<!-- Drop any empty elements -->
<xsl:template match="*[not(node())]" mode="copy" />


Current Thread