Re: [xml] [Possibly FAQ] XPath context node/relative paths



I now understand the silly mistake underlying my posted code -- of
course, 'path' will not match a path node, as it is a short-cut for
'child::path', as Kasimier Buchcik was kind enough to point out to me.

After discussing the issue a bit with Kasimier, I realise that what I
need is an implementation of XSLT match-patterns -- or something
similar. My use-case is actually quite similar to XSLT: I have a
document tree being built gradually, and have a set of rules/actions
that are to take place or not, depending on some predicate defined on
the last "parent" node (i.e., the node that other nodes are currently
being added to).

I see at least three possibilities, based on what I've found so far
(and very useful input from Kasimier):

  - Use absolute paths and check whether the node is found in the
    node-set.

  - Allow any XPath expression, "manually" evaluate it on the node in
    question and all its ancestor nodes, and check whether the node is
    found in any of the resulting node-sets.

    This is similar to the XSLT pattern semantics -- but in this
    simple solution none of the XSLT pattern syntactic constraints
    would be enforced. Also, it might be rather inefficient. (Going in
    "reverse", up the chain of ancestors, checking things
    incrementally, would certainly be better...)

  - Use pattern.c from libxml. This is, as far as I can see, XML
    Schema patterns, which are very restricted wrt. XSLT patterns.
    These seem to behave just the way I want, but the functionality
    may be a bit too restricted.

I guess I might look into libxslt to see if there is separate
functionality for XSLT patterns there -- I just though I'd check to
see if anyone here had any good tips (e.g. on using the libxml2 XPath
implementation in some way direectly).

Thanks,

- Magnus

-- 
Magnus Lie Hetland       Fallen flower I see / Returning to its branch
http://hetland.org       Ah! a butterfly.           [Arakida Moritake]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]