0

What is the best way to do an intersection with sxpath?

For example with the following XML:

<root>
  <a category="cat1">
    <b>some text</b>
    <b>foo <c>bar</c> baz</b>
  </a>
  <a category="cat1">
    <b>some other text</b>
    <b>x <c>y</c> z</b>
  </a>
  <a category="cat2">
    <b>foo <c>bar</c> baz</b>
  </a>
</root>

How would you use sxpath to select only b nodes that have cat1 parents and c children? That is an sxpath that would return:

((b "foo " (c "bar") " baz")
 (b "x " (c "y") " z"))
alinsoar
  • 15,386
  • 4
  • 57
  • 74
Antoine
  • 1,782
  • 1
  • 14
  • 32

1 Answers1

1

According to this document,

The XPath support provided for SXML in SXPath is fully compatible with the XPath Recommendation version 1.0.

So you can try one of the following expressions :

(sxpath "//b[parent::a[@category="cat1"]][./c]")
(sxpath "//b[..[@category="cat1"]][./c]")
(sxpath "//b[..[@*="cat1"]][./c]")

This should output 2 nodes :

((b "foo " (c "bar") " baz")
 (b "x " (c "y") " z"))
E.Wiest
  • 5,425
  • 2
  • 7
  • 12
  • Ok I didn't know guile's implementation of sxpath supported strings. :) – Antoine Jun 05 '20 at 14:57
  • 1
    I've edited my answer. The statement comes from SXML documentation. You have to check if guile offers this feature. Keep us updated.:) – E.Wiest Jun 06 '20 at 02:44