unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Ricardo Wurmus <rekado@elephly.net>
To: Matt Wette <matt.wette@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: SXML example showing diff between node-reduce and node-join
Date: Mon, 11 Jan 2021 23:01:25 +0100	[thread overview]
Message-ID: <871rerdtfu.fsf@elephly.net> (raw)
In-Reply-To: <2d53b553-c061-21c8-fef2-5dfb8a68bdfe@gmail.com>


Hi Matt,

> I'm going through the (sxml xpath) low-level routines to try to get a
> solid understanding of what they do.  I just can't come up with an example
> to show how node-reduce and node-join differ.   If someone could provide
> such an example I would really appreciate it.  Takers?

Here’s an example:

--8<---------------cut here---------------start------------->8---
(define sxml
  (xml->sxml "\
<foo>
  <bar>baz</bar>
  <wow>great</wow>
  <boo>
    <wow>
      <b>superb</b>
    </wow>
  </boo>
  <bye>
    <hello>
      <world>
        <excellent>
          <wow>today</wow>
        </excellent>
      </world>
   </hello>
  </bye>
  <greet>
    <hello>
      <world>
        <wow>yesterday</wow>
      </world>
    </hello>
  </greet>
</foo>"
             #:trim-whitespace? #true))

(define wow-converter
  (lambda (node-or-nodeset)
    (if (and (string? node-or-nodeset)
             (string=? "yesterday" node-or-nodeset))
        '(new "WOW!")
        node-or-nodeset)))

(define joined
  ((node-join (sxpath '(//))
              (node-trace "visiting")
              wow-converter
              (sxpath '(*text*)))
   sxml))

(define reduced
  ((node-reduce (sxpath '(//))
                (node-trace "visiting")
                wow-converter
                (sxpath '(*text*)))
   sxml))
--8<---------------cut here---------------end--------------->8---

The node-trace converter already shows that they behave differently.
The wow-converter only gets to see the plain string “yesterday” when it
is used with node-join.

Clearly, this is not the best example one could come up with, but I hope
it’s a start.

-- 
Ricardo



  reply	other threads:[~2021-01-11 22:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 13:44 SXML example showing diff between node-reduce and node-join Matt Wette
2021-01-11 22:01 ` Ricardo Wurmus [this message]
2021-01-11 22:07 ` tomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871rerdtfu.fsf@elephly.net \
    --to=rekado@elephly.net \
    --cc=guile-user@gnu.org \
    --cc=matt.wette@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).