Subject: Re: stripping leading and trailing blanks of a value?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Tue, 9 Mar 2010 09:33:52 -0800
|
This can be done easily even in XSLT 1.0 using the "trim" template of
FXSL (1.x).
For example, when this transformation (testTrim.xsl):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="trim.xsl"/>
<!-- to be applied on trim.xml -->
<xsl:output method="text"/>
<xsl:template match="/">
'<xsl:call-template name="trim">
<xsl:with-param name="pStr" select="string(/*)"/>
</xsl:call-template>'
</xsl:template>
</xsl:stylesheet>
is applied on this xml document:
<someText>
This is some text
</someText>
the following result is produced:
'This is some text'
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
On Tue, Mar 9, 2010 at 9:05 AM, Ben Stover <bxstover@xxxxxxxxxxx> wrote:
> Assume I have a XML doc where occasionally values appear with leading and
trailing blanks similar to
>
> <aaa>
> <bbb>
> '3 blanks'somevalue'4 blanks'
> </bbb>
> </aaa>
>
> Because blanks are probably removed by the mailing list system I put 'n
blanks' in the code above.
> In reality real blanks are meant.
>
> So how can I strip all such leading and trailing blanks (nad line breaks)
with XSLT?
>
> The stripping should applied only to "atomic" values. That means that blanks
between e.g.
> <aaa> and <bbb> should be kept. So the result should look like
>
> <aaa>
> <bbb>somevalue</bbb>
> </aaa>
>
> Moreover how can I strip all "atomic" blanks in a whole XML doc and not only
from a particular tag value?
>
> Ben
|