首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSLT:在XSpec中测试结果文档的内容?

XSLT:在XSpec中测试结果文档的内容?
EN

Stack Overflow用户
提问于 2015-03-17 18:58:34
回答 1查看 589关注 0票数 0

我正在编写一个程序,它使用XSLT,需要测试Xspec中的结果文档调用的内容。在下面的示例中,我想测试result.xml的内容。如果有可能的话,你该怎么做?

XML: test.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<root></root>

XSLT:结果-document.xsl

代码语言:javascript
复制
<?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:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-31 09:35:06

我在寻找同样的答案,但我怀疑这是XSpec实现方式的固有限制。

我怀疑解决办法是有一个不可测试的模板,它使用结果文档,然后在结果文档中使用一个匹配或调用模板,该模板可以被测试:

XSLT

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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不会真正地“测试result.xml的内容”;只是XSPEC本身中指定的输入的XSLT行为。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29107506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档