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: "dvint dvint@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 14 Oct 2021 14:23:02 -0000 |
For generic xml without a dtd or schema, there is no wrong XPath as who is to say that element might exist somewhere or sometime. It would be nice if there was a way to validate an XPath against a given did or schema to indicate a path would never exist.Sent from my Verizon, Samsung Galaxy smartphone -------- Original message --------From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: 10/14/21 6:45 AM (GMT-08:00) To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] My XPath mistakenly referenced an element that doesn't exist and I got no error message ... is this bad language design? 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="/"> B B B <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.B 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] My XPath mistakenly refer, Wendell Piez wapiez@ | Thread | Re: [xsl] My XPath mistakenly refer, Michael Kay mike@xxx |
Re: [xsl] My XPath mistakenly refer, Wendell Piez wapiez@ | Date | Re: [xsl] My XPath mistakenly refer, Graydon graydon@xxxx |
Month |