[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xml syntax for xpath
No, yesterday I decided to do what I would consider a stupid Schematron trick. Someone suggested that validating a particular constraint would be impossible because Schematron is not turing complete (not ISO schematron in this case, in the case of ISO schematron I think it depends as to what query language is bound to it) I figured it would be possible to do it since the things that Schematron lacks in Turing completeness is basically looping, and in this case the actual validation context was not unlimited so looping was unnecessary. However to make the assertions needed in Schematron I've figured out it will require 86 assertions with increasingly longer xpaths (this is basically splitting a string up by linefeeds and making sure that the string in between each line feed cannot be longer than 35 characters and also making sure that one does not have more than 43 lines. One line feed between lines. 86 assertions because there is a slight difference in xpaths if the last character in the string is a line feed or not) Rather than write the xpaths by hand I figured it made sense to generate them. I have also encountered this situation before where it would have made sense to generate xpaths rather than hand write them, at least if I was going to be doing a lot of them. For example the following two schematron report elements validate an EAN location number as being correctly structured: <sch:report test="@schemeID='EAN' and substring(.,13,1)!=0 and ((((10 - substring((substring(.,1,1) * 1 + substring(.,2,1) * 3) + (substring(.,3,1) * 1 + substring(.,4,1) * 3) + (substring(.,5,1) * 1 + substring(.,6,1) * 3) + (substring(.,7,1) * 1 + substring(.,8,1) * 3) + (substring(.,9,1) * 1 + substring(.,10,1) * 3) + (substring(.,11,1) * 1 + substring(.,12,1) * 3),string-length((substring(.,1,1) * 1 + substring(.,2,1) * 3) + (substring(.,3,1) * 1 + substring(.,4,1) * 3) + (substring(.,5,1) * 1 + substring(.,6,1) * 3) + (substring(.,7,1) * 1 + substring(.,8,1) * 3) + (substring(.,9,1) * 1 + substring(.,10,1) * 3) + (substring(.,11,1) * 1 + substring(.,12,1) * 3)),1)) + ((substring(.,1,1) * 1 + substring(.,2,1) * 3) + (substring(.,3,1) * 1 + substring(.,4,1) * 3) + (substring(.,5,1) * 1 + substring(.,6,1) * 3) + (substring(.,7,1) * 1 + substring(.,8,1) * 3) + (substring(.,9,1) * 1 + substring(.,10,1) * 3) + (substring(.,11,1) * 1 + substring(.,12,1) * 3))) - ((substring(.,1,1) * 1 + substring(.,2,1) * 3) + (substring(.,3,1) * 1 + substring(.,4,1) * 3) + (substring(.,5,1) * 1 + substring(.,6,1) * 3) + (substring(.,7,1) * 1 + substring(.,8,1) * 3) + (substring(.,9,1) * 1 + substring(.,10,1) * 3) + (substring(.,11,1) * 1 + substring(.,12,1) * 3))) != substring(.,13,1) )"> there is an improperly formatted EAN number. </sch:report> <sch:report test="@schemeID='EAN' and substring(.,13,1) =0 and substring((substring(.,1,1) * 1 + substring(.,2,1) * 3) + (substring(.,3,1) * 1 + substring(.,4,1) * 3) + (substring(.,5,1) * 1 + substring(.,6,1) * 3) + (substring(.,7,1) * 1 + substring(.,8,1) * 3) + (substring(.,9,1) * 1 + substring(.,10,1) * 3) + (substring(.,11,1) * 1 + substring(.,12,1) * 3),string-length((substring(.,1,1) * 1 + substring(.,2,1) * 3) + (substring(.,3,1) * 1 + substring(.,4,1) * 3) + (substring(.,5,1) * 1 + substring(.,6,1) * 3) + (substring(.,7,1) * 1 + substring(.,8,1) * 3) + (substring(.,9,1) * 1 + substring(.,10,1) * 3) + (substring(.,11,1) * 1 + substring(.,12,1) * 3)),1) != 0"> there is an improperly formatted EAN number. </sch:report> Somewhat mundane, but if doing a lot of it (for example modulus 10 functions might be useful - have not as yet thought out if it is doable but I am of the opinion that it is) might make sense to generate, transform, save xpath expressions in an easier to handle format. Probably XML is not the optimal way to store this information either, but for various reasons of being able to talk about it with other people I will be using XML. Also as noted these are something on the order of Stupid Schematron/ or stupid Xpath tricks, but what the hell, everybody needs a hobby. Cheers, Bryan Rasmussen On 6/21/06, Tatu Saloranta <cowtowncoder@y...> wrote: > --- bryan rasmussen <rasmussen.bryan@g...> wrote: > > > Hi, there have been various xml based syntaxes for > > Xpath over the > > year. Anyone have some pointers to these, I am > > basically hoping to > > store extremely complicated/long xpath expressions > > and don't see a > > reason to roll my own (other than IIRC the xml based > > syntaxes were not > > pretty). > > ... but wont XML-defined representations be, almost by > definition, even longer and more complicated? ;-D > > *duck* > > But seriously, are you planning to query these paths > using xquery; for storage it'd seem that xpath syntax > itself, stored as text (within xml or whatever) would > not be that bad a storage choice? > > -+ Tatu +- > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > ----------------------------------------------------------------- > The xml-dev list is sponsored by XML.org <http://www.xml.org>, an > initiative of OASIS <http://www.oasis-open.org> > > The list archives are at http://lists.xml.org/archives/xml-dev/ > > To subscribe or unsubscribe from this list use the subscription > manager: <http://www.oasis-open.org/mlmanage/index.php> > >
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|