Subject: Re: [xsl] junit test... for xslt2? From: Andrew Welch <andrew.j.welch@xxxxxxxxx> Date: Mon, 8 Mar 2010 10:22:50 +0000 |
On 8 March 2010 09:20, Dave Pawson <davep@xxxxxxxxxxxxx> wrote: > On 08/03/10 09:12, Andrew Welch wrote: > > >> Ultimately though, for checking the "correctness" of the result of a >> transform, I think you just need to execute XPaths against it, which >> are more tolerant of subtle changes in the output. That was the idea >> behind xchecker, which then became running xquery and transforms to >> overcome the limitations of what xpath can check. > > Would you expand on that a little please Andrew? > I can see (initially) that xpath comparisons would > be easier (ws etc), but what made you change to > 'running xquery and transforms'? > What was xpath missing? The idea behind xchecker is that each test returns true() or a sequence of true()s to pass, and fails if any item is the sequence is not true(). For example, checking each <para> with @type = 'simple' should not have a title: for $p in //para[@type eq 'simple'] return not(exists($p/title)) That returns a sequence of booleans. As any value other than true causes the test to fail, you can rewrite that to return a nicer message: for $p in //para[@type eq 'simple'] return if not(exists($p/title)) then true() else concat('Simple paras must not have titles: ', $p/@id) So now it returns a sequence of true()s and/or strings. Any values other than true are returned as the failure message, so it can be a complex as needed. There are no "asserts". Allowing transforms or xqueries to be just makes it easier to test what you need (say you need a variable) and construct a better failure message, and means you can test however you like.. comparing xml if you really wanted to, or just simple xpaths. > I'm thinking of testing the output of a single template > against an expected 'structure'. Using a schema aware transform you could add an "as" attribute to the template which refers to a custom type, or if using a basic processor just validate the result yourself. Using something like xchecker you could use straight xpaths, or use deep-equal() to compare expected and actual, or some other way you can think of thats possible using xslt or xquery. -- Andrew Welch http://andrewjwelch.com Kernow: http://kernowforsaxon.sf.net/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] junit test... for xslt2?, Dave Pawson | Thread | Re: [xsl] junit test... for xslt2?, Dave Pawson |
Re: [xsl] junit test... for xslt2?, Florent Georges | Date | Re: [xsl] How to emit opening and c, Wolfgang Laun |
Month |