specifying text node filtering rules

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

specifying text node filtering rules

Vasilis Vagenas

Hello! I wonder if the following is possible and cannot find an answer
to it. I use XQuery code to read an input XML document "in.xml" and
produce an output XML document "out.xml". I wonder if I can specify a
rule so that all text nodes copied from "in.xml" to "out.xml" are
filtered as follows: every group of consecutive whitespace characters
(tabs, new lines, spaces) are replaced by a single space character.
Given that text nodes are copied by many, diverse ways in my code, I
am not looking for a function manipulating strings (that should be
called whenever needed); this, apart from being a hardcoded procedure,
wouldn't be enough when copying element nodes containing text nodes in
their tree structures. Instead, I am looking for a way to specify a
general rule for filtering text nodes (e.g. like "declare
boundary-space strip;").

Thanks in advance.

Reply | Threaded
Open this post in threaded view
|

RE: specifying text node filtering rules

Michael Kay-3


XQuery does not offer rule-based processing of this kind. For that, you want
XSLT. In XSLT it's very easy to express this kind of rule:

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

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Vasilis Vagenas
> Sent: 13 December 2007 08:28
> To: [hidden email]
> Subject: specifying text node filtering rules
>
>
> Hello! I wonder if the following is possible and cannot find
> an answer to it. I use XQuery code to read an input XML
> document "in.xml" and produce an output XML document
> "out.xml". I wonder if I can specify a rule so that all text
> nodes copied from "in.xml" to "out.xml" are filtered as
> follows: every group of consecutive whitespace characters
> (tabs, new lines, spaces) are replaced by a single space character.
> Given that text nodes are copied by many, diverse ways in my
> code, I am not looking for a function manipulating strings
> (that should be called whenever needed); this, apart from
> being a hardcoded procedure, wouldn't be enough when copying
> element nodes containing text nodes in their tree structures.
> Instead, I am looking for a way to specify a general rule for
> filtering text nodes (e.g. like "declare boundary-space strip;").
>
> Thanks in advance.
>


Reply | Threaded
Open this post in threaded view
|

RE: specifying text node filtering rules

Vasilis Vagenas
In reply to this post by Vasilis Vagenas

Few lines of XSLT did perfect job indeed! Thanks a lot! Regards!