xsl-list
[Top] [All Lists]

Re: normalize-space and newlines

2005-08-23 21:32:28
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 
me,
in particular some persistent newlines.

...


The first XSL pass strips out any completely empty nodes, removes the 
<A>
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 
certain
<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 
now
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:copy>
<xsl:apply-templates select="@*|node()" mode="copy"/>
</xsl:copy>
</xsl:template>

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

Dave

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>