[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: normalize-space and newlines
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|