psilwen wrote:But how about to remove all attribute-list in different level of SXML?
This is more difficult, right?
What better way to do.
Before I start, a fair warning: sometimes my solutions are "more work" than the interpreter needs to do because I've failed to use a primitive that could have done the same thing. :) But barring that, here's an idea.
I assume you want to
clean (i.e. filter out) the attribute lists from your sxml. In doing so, you might use a predicate like this, with the primitive
clean, to identify the attribute lists.
Code: Select all
(define (is-attr-list? THING)
(and (list? THING)
(= '@ (first THING))))
However the
clean primitive is "too shallow" for the job, e.g.
Code: Select all
> [cmd]
(clean is-attr-list?
'("dl"
(@ ("class" "codebox"))
("dt" "Code: " ("a" (@ ("href" "#") ("onclick" "selectCode(this); return false;"))
"Select all"))
("dd" ("code" "(find-all '(bananas *) data)"))))
[/cmd]
("dl" ("dt" "Code: " ("a" (@ ("href" "#") ("onclick" "selectCode(this); return false;"))
"Select all"))
("dd" ("code" "(find-all '(bananas *) data)")))
>
It removes only the attribute list at the top level.
What is needed is something like a "deepening" form of
clean. I had tried doing something with the
replace primitive, but didn't have any luck; so I resorted to writing this new function instead.
Code: Select all
(define (deep-clean PREDICATE LIST)
(if (not (list? LIST))
LIST
(map (curry deep-clean PREDICATE)
(clean PREDICATE LIST))))
Now, you can get rid of all the attribute lists from your sxml.
Code: Select all
> [cmd]
(deep-clean is-attr-list?
'("dl"
(@ ("class" "codebox"))
("dt" "Code: " ("a" (@ ("href" "#") ("onclick" "selectCode(this); return false;"))
"Select all"))
("dd" ("code" "(find-all '(bananas *) data)"))))
[/cmd]
("dl" ("dt" "Code: " ("a" "Select all")) ("dd" ("code" "(find-all '(bananas *) data)")))
>
I hope that helps. Sorry for the long comment.