Hi Flibbles, Wow, that was fast! The ability to set namespace aliases in outer variables is very powerful.
As it is, I've already been able to retrieve deep data from ONIX documents, from an XHTML document (interesting interactions to explore with TW5 by the way) and from an Excel 2004 XML Stylesheet: not only your plugin works but it seems very fast already. However, even though I support your quest for unambiguity, I still miss a way to set the default namespace. I'm insisting on this because the XPath syntax is already abundant: adding prefixes to each step of the path while working on a single namespace document (probably the most common real-world case) may be somewhat discouraging. My early suggestion was unnecessarily complicated, but I know that being able to explicitly set *xmlns* in $xpath as the current default namespace, and/or set an *xmlns* outer variable/macro would be very valuable. Regarding ambiguity, my hope is that an *xmlns* variable would not be more ambiguous than, say, *currentTiddler*. Also, with your planned *value-of* attribute, one would have easily access to XPath functions like namespace-uri() in order to check where (s)he is when a path expression doesn't return anything. The most important is that your plugin is already wonderfully useful at this stage! So thank you again! Cheers, -- Xavier Cazin On Sat, May 2, 2020 at 11:36 PM Flibbles <[email protected]> wrote: > > Okay. I think I found the proper solution. I have examples and short > documentation here <https://flibbles.github.io/tw5-xml/>. Basically, when > elements have namespaces, whether explicit or default, the xpath wants a > prefix to go with it. In your use-case, you'd do this: > > <ul> > <$xpath xmlns:onix="http://ns.editeur.org/onix/3.0/reference" > xmlns:ns4="http://www.w3.org/1999/xhtml" > for-each="/onix:ONIXMessage/onix:Product/*/onix:Text/ns4:p/text()" > variable="foo"> > <li><<foo>></li> > </$xpath> > </ul> > > > It's a little more verbose than what you were proposing, but the upside is > that this will never suffer from ambiguous namespaces if multiple default > namespaces are used within one document. Also, you don't have to add onix: > prefixes throughout your own documents. > > I do have one neat trick though. That xmlns:onix attribute will be > available in all nested <$xpath> widgets. You could even define xmlns:onix > using <$set> or <$vars>. Or you can globally define it with \define > xmlns:onix() in a global macro tiddler. That should help trim down > verbosity. > > Unless you see a flaw with this, I *think* is is probably the way to go. > Now that I better understand namespaces, being explicit with all namespaces > in an XPath query actually makes sense to me. No ambiguity. Queries can > traverse documents with a litany of changing namespace scopes. > > -Flibbles > > -- > You received this message because you are subscribed to the Google Groups > "TiddlyWiki" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/tiddlywiki/dd7264cc-7dd6-4a3f-8417-ef1367042404%40googlegroups.com > <https://groups.google.com/d/msgid/tiddlywiki/dd7264cc-7dd6-4a3f-8417-ef1367042404%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/CADeSwYNe-caMa5Qd2QKP1-E4Un-1CHc7odUZBciAtFqNgBkL3g%40mail.gmail.com.

