
Hi there,
In XSLT there is an XPath function that will let you select a
particular node in the current context, for example;

Tom Spencer
In XSLT there is an XPath function that will let you select a particular node in the current context, for example;
This selects the first team element in the current context. Is there a work around to get similar functionality from the HaXml library?
It's easy to define, yes. Here is an "indexing" combinator that chooses one result of a CFilter, based on numeric position: index :: Int -> CFilter -> CFilter index n f = (\c-> [ (f c)!!n ]) So for your example, you want to write something like: index 0 (tag "team") `o` children This is probably the simplest way of doing your specific task, but there are of course other ways. The tool Xtract has a parser for XPath-like expressions, including more complex predicates, which get translated directly to combinator-style accessors. Unfortunately, the set of combinators used in Xtract is slightly different from those in the rest of HaXml, but they bear a close relationship. You could also use LabelFilters, e.g. (\cs-> ... cs!!0 ...) `oo` numbered (tag "team" `o` children) and doubtless there are other techniques too. Regards, Malcolm

This is probably the simplest way of doing your specific task, but there are of course other ways. The tool Xtract has a parser for XPath-like expressions, including more complex predicates, which get translated directly to combinator-style accessors. Unfortunately, the set of combinators used in Xtract is slightly different from those in the rest of HaXml, but they bear a close relationship.
Before i start, I apologise for the simplicity of these questions, here goes: I am just trying out a few things with the Xtract tool. I have a simple XML document: <greetings> <greeting>hello</greeting> <greeting>world</greeting> </greetings> I am using the Xtract query /greetings/greeting[1]/- hoping to get the text "world" e.g. mkElem "h1" [applypred (keep) (parseXtract "/greetings/greeting[1]/-")] but this just returns the entire xml document. Have i got something fundamentally wrong here? Thanks Tom Spencer
participants (2)
-
Malcolm Wallace
-
Tom Spencer