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

Re: Pattern-Matching / Regular Expression Types

Subject: Re: Pattern-Matching / Regular Expression Types
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 26 Apr 2012 23:05:55 +0100
Re:  Pattern-Matching / Regular Expression Types
On 26/04/2012 22:45, Tiago Freitas wrote:
I need to match patterns on a set of XML documents (all with the same
schema), and when a pattern matches, I need to retrieve the content
and do some specific transformations on that content (no xml output
needed).

Specifically, they are natural language syntactic trees (and dependencies).

I will have a list of those "patterns", that are similar to regular
expressions, but with elements and attributes.

pseudo-pattern example:

(//ELEMENTx) (node())* (//ELEMENTy[@ATTRIBUTEz]) (node())* (//@ATTRIBUTEw)

I used XPath syntax inside the parenthesis only. Other quantifiers
could be used...and also specify dependencies between
nodes/attributes, but that is another problem.

This example would match when the xml has ELEMENTx as the first
element, ends with one element that has ATTRIBUTEw, and in between
needs to have an ELEMENTy with ATTRIBUTEz.

Note that I need to match the whole document for each pattern, not
just part of it.

The nesting of elements does not matter in this case (ELEMENTy could
be a child of ELEMENTx, or not), but they need to have that specific
order (in document order).

Example of tree that can appear:
TOP
   / \
X   Y
| \   | \
1 2 3 4

Matching patterns could be (node names, assuming no attributes):
X Y
1 * Y
X 3 4
1 * 4

I could use XPath to get each individual node in the pattern, but then
I loose the order...if I do two XPath queries, I don't know the
positions of the results relative to each other.

After matching, I will have rules for each pattern, that specify some
transformations on the content (change order, etc).

Is there any way to do something like this using XSL, XQuery, or other
language? (preferably available in a Java implementation)

Thanks for any pointers.
(Is it ok to cross-post this to an XQuery list? Recommend any?)


It's actually very hard to understand your notation, but I think that you just want something like
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template name="main">

<xsl:variable name="x" select="//ELEMENTx"/>
<xsl:variable name="y" select="//ELEMENTy[@ATTRIBUTEz]"/>
<xsl:variable name="w" select="//*[@ATTRIBUTEw]"/>

<xsl:sequence select="
some $xi in $x satisfies
some $yi in $y satisfies
some $wi in $w satisfies
($xi  &lt;&lt; $yi) and ($yi  &lt;&lt; $wi)
"/>
</xsl:template>

which returns true for

<x>
<ELEMENTy ATTRIBUTEz="1"/>
<y><ELEMENTx/></y>
<ELEMENTy ATTRIBUTEz="2"/>
<k/>
<l/>
<KK ATTRIBUTEw=""/>
<y><ELEMENTx/></y>
</x>

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.