无法对生成具有嵌套元素的元素的 XSLT 模板规则进行单元测试
Unable to unit test an XSLT template rule that generates an element with nested elements
我有一个 XSLT 模板可以对此进行转换:
<WGS__LAT>N20340000</WGS__LAT>
对此:
<latitude>
<deg>20</deg>
<min>34</min>
<sec>00</sec>
<hSec>00</hSec>
<northSouth>North</northSouth>
</latitude>
我写了一个 XSpec 场景来测试 XSLT 模板:
<x:scenario label="location/latitude: Check that the XSLT assigns latitude the split-up value of WGS__LAT">
<x:context>
<WGS__LAT>N20340000</WGS__LAT>
</x:context>
<x:expect label="Expect: deg=20, min=34, sec=00, hSec=00, northSouth=North">
<latitude>
<deg>20</deg>
<min>34</min>
<sec>00</sec>
<hSec>00</hSec>
<northSouth>North</northSouth>
</latitude>
</x:expect>
</x:scenario>
我确定我的 XSLT 模板可以正常工作,但为什么 XSpec 工具报告失败?我认为这可能与 中的空格有关,所以我删除了所有空格:
<x:expect label="Expect: deg=20, min=34, sec=00, hSec=00, northSouth=North">
<latitude><deg>20</deg><min>34</min><sec>00</sec><hSec>00</hSec><northSouth>North</northSouth></latitude>
</x:expect>
不幸的是,我还是失败了。我做错了什么?
没有完整的报告,尤其是您实际得到的报告,很难回答。但 :
在这种情况下,一个可行的起点是将您的上下文包装在另一个标记中,并在 xspec 中设置结果的哪一部分应该匹配。像 :
<x:context>
<foo>
<WGS__LAT>N20340000</WGS__LAT>
</foo>
</x:context>
<x:expect label="..." test="/foo/*" as="element(latitude)">
<latitude>
<deg>20</deg>
<min>34</min>
<sec>00</sec>
<hSec>00</hSec>
<northSouth>North</northSouth>
</latitude>
</x:expect>
您可以查看 wiki 以更准确地使用期望值。
然后,用fn:deep-equals(...)
方法比较实际结果和预期结果。因此,没有对 result 或 expect 的输出处理。如果你在 x:context
或 x:expect
上使用 @href
,那么就会有一个 space 规范化,但我不太确定。
您可以查看 this issue 关于缩进问题;这是一个很长但仍然开放的话题。
我有一个 XSLT 模板可以对此进行转换:
<WGS__LAT>N20340000</WGS__LAT>
对此:
<latitude>
<deg>20</deg>
<min>34</min>
<sec>00</sec>
<hSec>00</hSec>
<northSouth>North</northSouth>
</latitude>
我写了一个 XSpec 场景来测试 XSLT 模板:
<x:scenario label="location/latitude: Check that the XSLT assigns latitude the split-up value of WGS__LAT">
<x:context>
<WGS__LAT>N20340000</WGS__LAT>
</x:context>
<x:expect label="Expect: deg=20, min=34, sec=00, hSec=00, northSouth=North">
<latitude>
<deg>20</deg>
<min>34</min>
<sec>00</sec>
<hSec>00</hSec>
<northSouth>North</northSouth>
</latitude>
</x:expect>
</x:scenario>
我确定我的 XSLT 模板可以正常工作,但为什么 XSpec 工具报告失败?我认为这可能与
<x:expect label="Expect: deg=20, min=34, sec=00, hSec=00, northSouth=North">
<latitude><deg>20</deg><min>34</min><sec>00</sec><hSec>00</hSec><northSouth>North</northSouth></latitude>
</x:expect>
不幸的是,我还是失败了。我做错了什么?
没有完整的报告,尤其是您实际得到的报告,很难回答。但 : 在这种情况下,一个可行的起点是将您的上下文包装在另一个标记中,并在 xspec 中设置结果的哪一部分应该匹配。像 :
<x:context>
<foo>
<WGS__LAT>N20340000</WGS__LAT>
</foo>
</x:context>
<x:expect label="..." test="/foo/*" as="element(latitude)">
<latitude>
<deg>20</deg>
<min>34</min>
<sec>00</sec>
<hSec>00</hSec>
<northSouth>North</northSouth>
</latitude>
</x:expect>
您可以查看 wiki 以更准确地使用期望值。
然后,用fn:deep-equals(...)
方法比较实际结果和预期结果。因此,没有对 result 或 expect 的输出处理。如果你在 x:context
或 x:expect
上使用 @href
,那么就会有一个 space 规范化,但我不太确定。
您可以查看 this issue 关于缩进问题;这是一个很长但仍然开放的话题。