如何从XSpec中的x:expect结果中删除test:ws元素

时间:2018-10-25 05:37:57

标签: xslt-2.0 xspec

xspec抛出的预期结果:

<nl/>
<test:ws xmlns:test="http://www.jenitennison.com/xslt/unit-test">
</test:ws>

我想要的预期结果是我们想要的输出元素:

<nl/>

1 个答案:

答案 0 :(得分:0)

您需要在XSLT中做三件事:

  1. 添加命名空间xmlns:test="http://www.jenitennison.com/xslt/unit-test"
  2. 排除名称空间exclude-result-prefixes="xs test"
  3. 为测试写空模板:ws <xsl:template match="test:ws"/>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <nl/>
    <test:ws xmlns:test="http://www.jenitennison.com/xslt/unit-test"></test:ws>
</root>

XSLT:

<?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"
    xmlns:test="http://www.jenitennison.com/xslt/unit-test"
    exclude-result-prefixes="xs test" version="2.0">

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="test:ws"/>

</xsl:stylesheet>

输出:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <nl/>

</root>

请参阅下面提到的链接以供参考:

https://xsltfiddle.liberty-development.net/jyH9rNa