[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: normalize-space and newlines

Subject: Re: normalize-space and newlines
From: david_n_bertoni@xxxxxxxxxx
Date: Wed, 24 Aug 2005 00:32:28 -0400
framemaker structured empty elements error
> 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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.