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

Re: using normalize-space with mixed element content

Subject: Re: using normalize-space with mixed element content
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Wed, 09 Jun 2010 00:52:10 +0200
Re:  using normalize-space with mixed element content
If you want to treat the first / last text nodes of article-title, no matter how deep they are nested in other elements:

  <xsl:template match="article-title//text()[
                         generate-id() eq (
                           for $t in ancestor::article-title//text()
                           return generate-id($t)
                         )[last()]
                       ]"
    mode="none" priority="100">
    <xsl:value-of select="replace(., '\s+$', '')"/>
  </xsl:template>

  <xsl:template match="article-title//text()[
                         generate-id() eq (
                           for $t in ancestor::article-title//text()
                           return generate-id($t)
                         )[1]
                       ]"
    mode="none" priority="101">
    <xsl:value-of select="replace(., '^\s+', '')"/>
  </xsl:template>

  <xsl:template match="article-title//text()[
                         generate-id() eq (
                           for $t in ancestor::article-title//text()
                           return generate-id($t)
                         )[last() = 1]
                       ]"
    mode="none" priority="102">
    <xsl:value-of select="normalize-space(.)"/>
  </xsl:template>


On 09.06.2010 00:44, Michael Kay wrote:
Sorry, I got that wrong. You can't remove leading whitespace from the
first text node if it is preceded by an element:

<p><i>Some</i> thing is wrong!</p>

What I meant was, you can safely remove leading whitespace from a text
node if it is the first child node:

<xsl:template
match="title-group/article-title/text()[not(preceding-sibling::node())]"
priority="100">
<xsl:value-of select="replace(., '^\s+', '')"/>
</xsl:template>

and similarly for a text node with no following siblings.

Michael Kay
Saxonica

On 08/06/2010 23:37, Michael Kay wrote:
A crude way would be to use normalize-space() only if there are no
element children:

<xsl:template match="title-group/article-title[not(*)]" mode="none">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>

<xsl:template match="title-group/article-title[*]" mode="none">
<xsl:copy-of select="."/>
</xsl:template>

More subtle is to recognize that you can safely remove leading
whitespace from the first text node, and trailing whitespace from the
last:

<xsl:template match="title-group/article-title/text()[1]" priority="100">
<xsl:value-of select="replace(., '^\s+', '')"/>
</xsl:template>

<xsl:template match="title-group/article-title/text()[last()]"
priority="101">
<xsl:value-of select="replace(., '\s+$', '')"/>
</xsl:template>

<xsl:template match="title-group/article-title/text()[last()=1]"
priority="102">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>

Michael Kay
Saxonica




On 08/06/2010 23:24, Lynn Murdock wrote:
hi-

i want to remove trailing whitespace from the contents of an element
(<article-title>), but because that element sometimes contains
character-level formatting elements (<italic>) as well as text,
normalize-space is creating problems. if i use normalize-space(), i
lose the italics in the output. (i'm transforming to html.)

here's an example of where i want to remove whitespace (i want to
remove the space before</article-title>):

<title-group>
<article-title>Effect of a Brief Video Intervention on Incident
Infection among Patients Attending Sexually Transmitted Disease
Clinics</article-title>
</title-group>

and here's the xsl code i've used:

<xsl:template match="title-group/article-title" mode="none">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>

this code works most of the time, but in a situation like this:

<article-title>A Global Survey of Gene Regulation during Cold
Acclimation in<italic>Arabidopsis</italic>
<italic>thaliana</italic></article-title>

it ends up removing the italic formatting.

does anyone know of a way to strip the whitespace that i don't want
(in the first example) while keeping the character formatting that i
do want (in the second example)?

any pointers would be greatly appreciated.


thanks-


lynn
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This email is confidential to the intended recipient. If you have
received it in error, please notify the sender and delete it from your
system. Any unauthorized use, disclosure or copying is not permitted.
The views or opinions presented are solely those of the sender and do
not necessarily represent those of Public Library of Science unless
otherwise specifically stated. Please note that neither Public Library
of Science nor any of its agents accept any responsibility for any
viruses that may be contained in this e-mail or its attachments and it
is your responsibility to scan the e-mail and attachments (if any).


-- Gerrit Imsieke Geschdftsf|hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vvckler

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.