This simple library can help you test your XSL stylesheets against different XML document and assert the validity of transformations using XPath expressions.
You add this to your pom.xml
:
<dependency>
<groupId>org.eolang</groupId>
<artifactId>xax</artifactId>
<version>0.5.1</version>
</dependency>
Then, create this XSL file in src/main/resources/simple.xsl
:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="foo">
<xsl:copy>
<xsl:text>bye</xsl:text>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*" mode="#default">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Then, create this YAML file in src/test/resources/simple.yaml
:
sheets:
- simple.xsl
document:
<doc><foo>hello</foo></doc>
asserts:
- /doc/foo[.='bye']
Finally, make a unit test (using
JUnit5,
Hamcrest,
and @ClasspathSource
from Jucs):
import org.eolang.jucs.ClasspathSource;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.params.ParameterizedTest;
final class MyTest {
@ParameterizedTest
@ClasspathSource(value = "", glob = "**.yaml")
void itWorks(String yaml) {
MatcherAssert.assertThat(
new XaxStory(yaml),
Matchers.is(true)
);
}
}
Should work.
Fork repository, make changes, send us a
pull request.
We will review your changes and apply them to the master
branch shortly,
provided they don't violate our quality standards. To avoid frustration,
before sending us your pull request please run full Maven build:
mvn clean install -Pqulice
You will need Maven 3.3+ and Java 8+.