Subject: Re: [xsl] using normalize-space with mixed element content From: David Carlisle <davidc@xxxxxxxxx> Date: Tue, 08 Jun 2010 23:39:01 +0100 |
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
so you just apply this to the last node, if it's text. and you want to remove trailing white space
<xsl:variable name="x" select="normalize-space(concat(.,'x'))"/> <xsl:value-of select="substring($x,1,string-length($x)-1)"/> </xsl:template>
<xsl:template match="title-group/article-title[not(*)]" mode="none"> <xsl:value-of select="normailze-space(.)"/> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] using normalize-space wit, David Carlisle | Thread | [xsl] using normalize-space with mi, Lynn Murdock |
Re: [xsl] using normalize-space wit, Michael Kay | Date | Re: [xsl] using normalize-space wit, Michael Kay |
Month |