[ssax-sxml] Re: How can I access attributes in "stylesheets"
Brought to you by:
oleg
From: <ol...@po...> - 2003-08-11 18:56:56
|
Hello! > I'm curious though, is there any way to make this a bit more terse? One > concept I think I'd like would be: > (define main-ss > `((some-sxpath-fn ...) ,(lambda (tag . kids) ...))) The interesting question is what to do if several some-sxpath-fn apply at some point during traversal. How to figure out which handler to call? XSLT resolves ambiguities based on priorities, modes, and the import order. I personally have an impression that it is ad hoc (especially assigning priorities to different components of XPath). > o> So, in your example: > o> (define doc '(some-tag (@ (key value)) "some text")) > o> (define main-ss > o> `((some-tag *preorder* > o> . ,(lambda tag . kids) > o> ; the first kid is the collection of attrs > o> (let ((attrs (cdar kids)) > o> (proper-children (cdr kids))) > o> (if (assq 'key attrs) > o> (pre-post-order `(,tag . ,kids) > o> a-style-sheet-to-use-if-key-present > o> a-style-sheet-to-use-if-key-not-present)))))) > So, I guess my question comes down to this - how can I do the above code > in a more concise way? Nothing precludes us from defining a function such as 'check-attr-and-redirect' so we can write the handler as ((some-tag *preorder* . ,(lambda node (check-attr-and-redirect node 'key a-style-sheet-to-use-if-key-present a-style-sheet-to-use-if-key-not-present)))) If criteria are very complex, we can use SXPath: something like the following. ((some-tag *preorder* . ,(lambda node ((sxpath `(@or (* (sxpath-test1) transformer1) (* (sxpath-test2) transformer2))) node)))) where a transformer takes a nodelist (of one node -- the current node), and should return a nodelist with a transformed node. I need to check if returning the nodelist with several result nodes is OK. My hunch is that it should be, at least as far as further SXSLT transformations are concerned. Cheers, Oleg |