xsl-list
[Top] [All Lists]

RE: [xsl] Need help OR'ing in XPATH.

2006-03-23 10:31:56
Vasu,

At the risk of seeming like I'm piling on....

My difficulty with your recommendation is that it works to solve a problem we don't actually have. My notion of "best practice" is that it's fair to assume that best practice is also being followed elsewhere in the system. This isn't to say that good code is not fault-tolerant: it is. But there is a principle of parsimony here: solving problems that don't actually exist, and which (if they do) are better solved elsewhere in the system in any case, is just wasted energy.

Your hypothetical problem actually illustrates this perfectly. You pose us with the possibility that instead of

<chapter>
  <owner>aaa</owner>
</chapter>

we get

<chapter>
  <owner>aaa<id>222</id></owner>
</chapter>

and point out that the expression "chapter/owner/text='aaa'" will succeed in either case, whereas "chapter/owner='aaa'" will not.

But what if, no more hypothetically, we get

<chapter>
  <owner><who>aaa</who></owner>
</chapter>

In this case, "chapter/owner='aaa'" will work, but "chapter/owner/text()='aaa'" will fail.

This just goes to show that once we start solving problems that don't exist, there's no end to it, since we're just as likely to create more problems as we are to solve anything.

The real solution to the problem of managing unpredictable variation in the format of your incoming XML is to manage it: design your stylesheet to accept data conforming to a schema (or a set of constraints formalized and checkable by some other means), and then validate your input to that schema.

In doing so, you might make sure that data that needs to be labelled is properly labelled, and doesn't appear floating around in arbitrary mixed content. Then your XSLT has an easy time of it.

Cheers,
Wendell



======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--