XSLT:在 XSpec 中测试结果文档的内容?
XSLT: Test the contents of a result-document in XSpec?
我正在编写一个使用 XSLT 的程序,需要在 Xspec 中测试结果文档调用的内容。在下面的示例中,我想测试 result.xml 的内容。如果可以的话,你是怎么做到的?
XML: test.xml
<?xml version="1.0" encoding="UTF-8"?>
<root></root>
XSLT:结果-document.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">
<xsl:template match="/root">
<xsl:result-document href="result.xml">
<my-result></my-result>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
XSpec:
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="result-document.xsl">
<x:scenario label="Test result document">
<x:context href="test.xml"></x:context>
<!-- How do you test the result.xml file here? -->
<x:expect label="test result">
<my-result></my-result>
</x:expect>
</x:scenario>
</x:description>
我一直在寻找相同的答案,但我怀疑这是 XSpec 实现方式的固有限制。
我怀疑解决方法是使用一个使用结果文档的不可测试模板,然后在可以测试的结果文档中使用匹配或调用模板:
XSLT
<xsl:template match="/root">
<xsl:result-document href="result.xml">
<xsl:call-template name="my-result"/>
</xsl:result-document>
</xsl:template>
<xsl:template name="my-result">
<!-- content -->
</xsl:template>
XSPEC
<x:scenario label="when calling my-result">
<x:call template="my-result"/>
<x:expect label="test something" pending="add your tests here"/>
</x:scenario>
所以你无法真正测试结果文档是否以正确的方式制作,但你可以检查它们的结果。
请注意,XSPEC 不会按字面意思 "test the contents of result.xml";只是 XSLT 对您在 XSPEC 本身中指定的输入的行为。
我正在编写一个使用 XSLT 的程序,需要在 Xspec 中测试结果文档调用的内容。在下面的示例中,我想测试 result.xml 的内容。如果可以的话,你是怎么做到的?
XML: test.xml
<?xml version="1.0" encoding="UTF-8"?>
<root></root>
XSLT:结果-document.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">
<xsl:template match="/root">
<xsl:result-document href="result.xml">
<my-result></my-result>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
XSpec:
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="result-document.xsl">
<x:scenario label="Test result document">
<x:context href="test.xml"></x:context>
<!-- How do you test the result.xml file here? -->
<x:expect label="test result">
<my-result></my-result>
</x:expect>
</x:scenario>
</x:description>
我一直在寻找相同的答案,但我怀疑这是 XSpec 实现方式的固有限制。
我怀疑解决方法是使用一个使用结果文档的不可测试模板,然后在可以测试的结果文档中使用匹配或调用模板:
XSLT
<xsl:template match="/root">
<xsl:result-document href="result.xml">
<xsl:call-template name="my-result"/>
</xsl:result-document>
</xsl:template>
<xsl:template name="my-result">
<!-- content -->
</xsl:template>
XSPEC
<x:scenario label="when calling my-result">
<x:call template="my-result"/>
<x:expect label="test something" pending="add your tests here"/>
</x:scenario>
所以你无法真正测试结果文档是否以正确的方式制作,但你可以检查它们的结果。
请注意,XSPEC 不会按字面意思 "test the contents of result.xml";只是 XSLT 对您在 XSPEC 本身中指定的输入的行为。