-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot compare whole documents #227
Comments
You expect that a serialized result is equal to another serialized doc when both are parsed again. <x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
stylesheet="article-to-html.xsl" xslt-version="3.0">
<x:scenario label="The integration test output">
<x:context href="article.xml"/>
<x:expect label="serialized result should match the expected result when parsed" href="article_expected.html"
test="
.
=> serialize(
map {
'method': 'xhtml',
'indent': true(),
'html-version': 5.0
}
)
=> parse-xml()"/>
</x:scenario>
</x:description> (For more completeness, you may want to generate the serialization parameters dynamically from the stylesheet |
|
Note that in your screenshot, the right-hand Expected Result has To make the test result Success, you should either fix the stylesheet to produce a document node <xsl:template match="/">
<xsl:document><xsl:apply-templates/></xsl:document>
</xsl:template> or fix <x:expect label="should match the expected element." href="article_expected.xml" select="element()"/> whichever meets your actual goal. |
Hi, thanks for your replies @AirQuick! Regarding your latest comment: I wasn't aware of the However, I also didn't knew, that without a root template with a Removing the root remplate and using Now the next step is to take a closer look at the serialized results. Thanks, Tobias |
Unfortunately, this doesn't work for me. The "result" is always empty Any ideas? |
Okay, this seems to be an issue with the serialization parameter |
What is your Saxon edition and version? My example worked on Saxon-EE 9.8.0.12 and 9.8.0.14 on my end. |
Looks like Saxon
|
I was running Saxon-HE 9.8.0.7. Now I'm using 9.8.0.14 and it works with the serialization parameter |
Next question: Is it somehow possible to a) ignore indentation whitespace or any other whitespace differences when comparing the result document and expected document? b) ignore certain special elements within a document? (e.g. a timestamp element)? |
Regarding b) I was able to come up with the following solution to only compary partial trees of result and expected: <?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:html="http://www.w3.org/1999/xhtml"
stylesheet="../xslt/docbook-to-html-serialized.xsl" xslt-version="3.0">
<x:scenario label="The integration test">
<x:context href="demo2/article.xml"/>
<x:expect label="should match the expected result." href="demo2/article.html" select="/html:html/html:body"
test="
/html:html/html:body
=> serialize(
map {
'method': 'xhtml',
'indent': true(),
'html-version': 5.0
}
)
=> parse-xml()"/>
</x:scenario>
</x:description> But it only works partially. The expected result (via |
I think what you really want to extract from the actual result is this <x:expect label="/html/body should match the expected result."
href="demo2/article.html"
select="/html:html/html:body"
test="
(
.
=> serialize(
map {
'method': 'xhtml',
'indent': true(),
'html-version': 5.0
}
)
=> parse-xml()
)/html:html/html:body"/> |
The three dot feature mentioned in Wiki could help to some extent. I'm not aware of a built-in feature beyond that. When I have to verify complicated things, I usually write a wrapper XSLT. For example, if I have to test wrapper.xsl <xsl:stylesheet xmlns:my="my">
<!-- Test target -->
<xsl:include href="../src/actual.xsl" />
<!-- Test helper -->
<xsl:function name="my:test-filter" as="element(baz)">
<xsl:param name="input" as="element(baz)" />
<!-- do whatever filtering on $input and return the filtered one -->
</xsl:function>
</xsl:stylesheet> test.xspec <x:description stylesheet="wrapper.xsl" xmlns:my="my">
<x:scenario>
<x:context><foo/></x:context>
<x:expect test="my:test-filter(/bar/baz)"><baz/></x:expect>
</x:scenario>
</x:description> This usually works for me, although I might have a bug in |
Awesome! 👏 Both of these solutions work very well! I totally forgot about the "three dot" feature ;-) |
That is already done for whitespace-only text nodes, when you write XML within <x:context>	

 <foo/></x:context> and <x:context><foo/></x:context> are treated equal. |
Alright, that sounds reasonable. Thanks a lot for your support, @AirQuick! We did a team training for XSpec and I think we will come up with a couple of changes and additions to the wiki docs. Stay tuned. Best, Tobias |
The garbage |
Hi,
I tried to use XSpec to compare a whole document with an expected result but have multiple issues.
This is my setup:
article.xml
article-to-html.xsl
This is what oXygen 20 (Saxon 9.8.0_8) produces as output:
article_expected.html
Then I wrote an XSpec scenario to compare actual transformation result with expected result from oXygen:
article-to-html.xspec
First of all: the results do not match:
Obviously it's because of the indentation which is different when the XSpec framework transforms the data.
However, if I remove the
indent="yes"
or change to "no", it doesn't get any better.Second: The
method="xhtml"
produces a<meta>
element in oXygen which is totally missing in the XSpec result, as you can see on the screenshot.Third: If I change the output declaration to
<xsl:output encoding="UTF-8" indent="no" method="xml"/>
the XSpec result seems to match the expected result from oXygen, all highlights in the HTML report are green, but the test fails anyway:This seems like a bug to me.
Fourth: When looking at the XML report, there are lots of empty
<test:ws xmlns:pkg="http://expath.org/ns/pkg">
elements which seem to be irrelevant and should be removed, right?How can both of these issues be resolved?
How can I compare whole documents as kind of an "integration test"?
Thanks,
Tobias
The text was updated successfully, but these errors were encountered: