Subject: Re: [xsl] My XPath mistakenly referenced an element that doesn't exist and I got no error message ... is this bad language design? From: "Alan Painter alan.painter@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 14 Oct 2021 16:39:29 -0000 |
I wanted to put a plug in for the schema-aware usage. When I was working with a team converting one complex vocabulary to another complex vocabulary, the error reporting from the schema-aware processing was incredibly helpful. Obviously, this only works for cases where those vocabularies exist, but in those cases, schema-aware error reporting is a fabulous tool. On Thu, Oct 14, 2021 at 6:22 PM Dimitre Novatchev dnovatchev@xxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > Even adding req() as a synonym for one-or-more() might be enough to > encourage people to write req(Document)/req(foo) in order to get better > diagnostics. > > Why not just: > > req(Document/foo) > > > Thanks, > Dimitre > > On Thu, Oct 14, 2021 at 8:17 AM Michael Kay mike@xxxxxxxxxxxx < > xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > >> Having said all this, of course you (and your friend) are perfectly >> correct: the fact that "void paths" are not statically detected is a major >> cause of debugging headaches, and a solution to the problem that prevents >> those headaches would be highly desirable. >> >> I've sometimes wondered whether a "soft" checker (lint-like) that warns >> you of potentially void paths (by reference to a schema and/or instance >> document) might not be a valuable tool. >> >> Or a run-time checker might be less complicated than a compile-time >> checker: Add an option selection="strict" at the xsl:transform level, and >> then >> >> Document/foo is treated as one-or-more(Document)/one-or-more(foo) >> >> while if you want zero-or-more(Document)/zero-or-more(foo) >> >> then you have to use some new syntax like opt(Document)/opt(foo) >> >> Even adding req() as a synonym for one-or-more() might be enough to >> encourage people to write req(Document)/req(foo) in order to get better >> diagnostics. >> >> Or perhaps a "\" operator that behaves like "/" except the RHS is not >> allowed to be empty. >> >> Michael Kay >> Saxonica >> >> > On 14 Oct 2021, at 16:06, Michael Kay mike@xxxxxxxxxxxx < >> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: >> > >> > This was the thinking that led to the design of the "static typing" >> feature in XQuery 1.0, which has been a notable failure. Even it its >> diluted form as implemented in schema-aware XPath/XQuery without static >> typing (where Saxon will potentially give you a warning here) it has not >> been a conspicuous success. >> > >> > The main reason, I think, is it requires extra coding effort up-front, >> and only gives you returns when debugging, later, if you don't get things >> right first time. Not many people are prepared to make that investment. >> > >> > Looking at your example, match="/" will match the document node of any >> XML document, whatever its type. To catch an error here, you first have to >> make it clear that the rule is only intended to apply to a particular kind >> of document, for example by writing >> > >> > match="document-node(schema-element(Document))" >> > >> > which is quite a bit more verbose than your original; and it also >> requires you (a) to import the schema for this document type, and (b) to >> validate the instance against the schema before applying the stylesheet. >> > >> > I would still encourage people to do that: it will detect many of your >> coding mistakes. But realistically, we're all inclined to take the path of >> least resistance, even if that path leads you into dragon-infested >> territory. >> > >> > Michael Kay >> > Saxonica >> > >> >> On 14 Oct 2021, at 14:45, Roger L Costello costello@xxxxxxxxx < >> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: >> >> >> >> Hi Folks, >> >> >> >> Here is my (very simple) XML document: >> >> >> >> <Document>Hello, world</Document> >> >> >> >> My XSLT program contains a xsl:value-of with a simple XPath expression: >> >> >> >> <xsl:template match="/"> >> >> <xsl:value-of select="Document/foo eq 'abc'"/> >> >> </xsl:template> >> >> >> >> In the XPath expression I mistakenly referenced an element -- foo -- >> that does not exist. >> >> >> >> I ran the XSLT program on the XML document. No error was generated. >> >> >> >> My colleague argues that such behavior is bad language design: >> >> --------------------------------------------------- >> >> Languages which define such mistakes to just return "empty" node lists >> or false, or such are not helping anybody. They just turn author mistakes >> into silent, hard-to-detect behaviors. In my view this is a major mistake >> in the XPath language. >> >> >> >> All path expressions should be strongly, statically type-correct, so >> Document/foo has to be a possible path. But if element foo is optional, >> then any given instance may not have element foo and so a path like >> Document/foo can be type correct, but meaningless for a particular data >> document. One can explicitly test, e.g., >> >> >> >> if ( exists(Document/foo) ) then (Document/foo eq 'abc') else.... >> >> >> >> If you just use the expression without this test, and node foo doesn't >> exist, then it should cause a failure. >> >> --------------------------------------------------- >> >> >> >> Do you agree with my colleague's assessment? Is this behavior in XPath >> an indication of bad language design? >> >> >> >> /Roger >> >> >> >> >> > >> > >> >> >> > > -- > Cheers, > Dimitre Novatchev > --------------------------------------- > Truly great madness cannot be achieved without significant intelligence. > --------------------------------------- > To invent, you need a good imagination and a pile of junk > ------------------------------------- > Never fight an inanimate object > ------------------------------------- > To avoid situations in which you might make mistakes may be the > biggest mistake of all > ------------------------------------ > Quality means doing it right when no one is looking. > ------------------------------------- > You've achieved success in your field when you don't know whether what > you're doing is work or play > ------------------------------------- > To achieve the impossible dream, try going to sleep. > ------------------------------------- > Facts do not cease to exist because they are ignored. > ------------------------------------- > Typing monkeys will write all Shakespeare's works in 200yrs.Will they > write all patents, too? :) > ------------------------------------- > Sanity is madness put to good use. > ------------------------------------- > I finally figured out the only reason to be alive is to enjoy it. > > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/552232> (by > email <>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] My XPath mistakenly refer, Michael Kay mike@xxx | Thread | Re: [xsl] My XPath mistakenly refer, BR Chrisman brchrism |
Re: [xsl] My XPath mistakenly refer, Michael Kay mike@xxx | Date | Re: [xsl] My XPath mistakenly refer, BR Chrisman brchrism |
Month |