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

Re: Removing nodes with text content ?

Subject: Re: Removing nodes with text content ?
From: Torsten Schassan <schassan@xxxxxx>
Date: Wed, 03 Aug 2011 17:25:03 +0200
Re:  Removing nodes with text content ?
Hi Fabien,

as Martin's answer didn't let you get rid of the line breaks,

I would like to remove the intermediary<phrase>  nodes to avoid line
breaks (which are highly desirable on other places, but here are
annoying me), and thus having everything on a single line (using the
docbook stylesheets, already customized).

a very specific, thus "inelegant" full "answer" below, but some additional hints anyway:


- to avoid line breaks in the output using normalize-space() is often useful
- xsl:strip-space might help as well.


<xsl:template match="phrase[@role='rtf']">
    	<xsl:copy>
    		<xsl:apply-templates select="./*"/>
    	</xsl:copy>
</xsl:template>

1. If you want to remove the element, you shouldn't copy it. (On the other hand, the template for para lacks this.)


2. Why wasn't text in the output? Your select selects only element nodes. In the more general template you use correctly "node()".

This should be working then (XSLT1):

<xsl:output indent="yes"/>

<xsl:template match="para">
<xsl:copy>
<phrase>
<xsl:if test=".//phrase[@role='rtf']">
<xsl:attribute name="role">rtf</xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</phrase>
</xsl:copy>
</xsl:template>
<xsl:template match="phrase[@role='rtf']" >
<xsl:apply-templates select="node()"/>
<xsl:if test="following-sibling::phrase"><xsl:text> </xsl:text></xsl:if>
</xsl:template>


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

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


Best, Torsten


--
Torsten Schassan
Digitale Editionen
Abteilung Handschriften und Sondersammlungen
Herzog August Bibliothek, Postfach 1364, D-38299 Wolfenbuettel
Tel.: +49-5331-808-130 (Fax -165), schassan {at} hab.de

http://www.hab.de/forschung/projekte/europeana-regia.htm
http://www.hab.de/forschung/projekte/weiss64.htm

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.