[liblouis-liblouisxml] Re: Bert, what could cause an XPath expression to return an empty node set?

Hi all

I suspect this is a namespace problem. If you look at the xml that Bert
provided, you'll see that there is a default namespace:

<dtbook xmlns="http://www.daisy.org/z3986/2005/dtbook/";

Now if you try to match a xpath such as '//level/h' libxml will use a
null namespace and will hence not match and return an empty nodeset. You
would have to match something like '//dtb:level/dtb:h'. But in order for
this to work you will have to register the namespaces (e.g.
'http://www.daisy.org/z3986/2005/dtbook/') and their prefixes ('dtb')
with libxml by using the xmlXPathRegisterNs call (see
http://xmlsoft.org/examples/xpath1.c for an example). This would
probably require that prefix and namespace can be specified somewhere in
the sem file.

Another way to make sure the xpath matches is to use the local-name()
xpath function where you specify the xpath in a namespace-independent
way:

heading1 &xpath(//*[local-name()='level']/*[local-name()='h'])

This returns a nodeset and seems to do something. It's not quite there
yet as the brl contains the xpath expression but at least it's closer to
where we want to go:

eglic@saadawi:~/src/liblouisxml$ libtool --mode=execute tools/xml2brl -f 
tests/bert.cfg tests/bert.xml
xpath
xpath
xpath
xpath
xpath
xpath
            ,n def9$ ,title

            ,n def9$ ,cr1tor

_+//*[local-name()='level']/*[local-nam-
         e()='h']Heading_: #a.a

  ,a l9e

_+//*[local-name()='level']/*[local-nam-
         e()='h']Heading_: #b.a

  ,a l9e

_+//*[local-name()='level']/*[local-nam-
         e()='h']Heading_: #b.b

  ,a l9e

_+//*[local-name()='level']/*[local-nam-
         e()='h']Heading_: #a.b

  ,a l9e

_+//*[local-name()='level']/*[loca-   #a
      l-name()='h']Heading_: #b.c

  ,a l9e

_+//*[local-name()='level']/*[local-nam-
         e()='h']Heading_: #c.a

  ,a l9e

_+//*[local-name()='level']/*[local-nam-
         e()='h']Heading_: #d.a

  ,a l9e

_+//*[local-name()='level']/*[local-nam-
         e()='h']Heading_: #e.a

  ,a l9e

_+//*[local-name()='level']/*[local-nam-
         e()='h']Heading_: #f.a

  ,a l9e

                                      #b

Hope that helps
Christian
-- 
Christian Egli
Swiss Library for the Blind, Visually Impaired and Print Disabled
Grubenstrasse 12, CH-8045 Zürich, Switzerland
For a description of the software and to download it go to
http://www.jjb-software.com

Other related posts: