我的 XML 数据应如下所示:
<mixed_type_parent>
...text...
<other_element1/>
<other_element2/>
<element_in_question>...some content...</element_in_question>
<other_element2>...text...</other_element2>
<other_element1>...text...</other_element1>
...text...
</mixed_type_parent>
我想确保使用 Schematron 是,如果“element_in_question”之外有一些文本,“element_in_question”可能只会出现在“mixed_type_parent”中。这意味着
<mixed_type_parent>
<element_in_question>...some content...</element_in_question>
</mixed_type_parent>
是不允许的,应该会导致错误。
我试图立即在“mixed_type_parent”中获取所有文本的字符串长度
string-length(replace(ancestor::mixed_type_parent[1]/text(),' ', ''))
但是,XPath 中还有一个最烦人的错误:“不允许将多个项目的序列作为 replace() 的第一个参数”
在 XSLT 中,我通过你能想到的最简单的函数解决了这个问题:
<xsl:function name="locfun:make_string">
<xsl:param name="input_sequence"/>
<xsl:value-of select="$input_sequence"/>
</xsl:function>
(在 XPath 中似乎没有这样的内置函数真的很遗憾。)
但是如何在 Schematron 中使用这个功能呢?我没有找到解决方案。
除此之外:除了“mixed_type_parent”之外,如何从“mixed_type_parent”的所有其他孩子中获取所有文本?