0

我的 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”的所有其他孩子中获取所有文本?

4

2 回答 2

2

尝试这个:

string-join(ancestor::mixed_type_parent[1]/text(),'')=''

对于您的第二个问题:除了“mixed_type_parent”之外,如何从“mixed_type_parent”的所有其他孩子中获取所有文本?

/mixed_type_parent/*[not(self::element_in_question)]/text()
于 2014-02-06T09:15:51.177 回答
0

考虑到这个输入 XML,

<mixed_type_parent>
    <element_in_question>...some content...</element_in_question>
</mixed_type_parent>

应用此 XSLT 时:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

<xsl:strip-space elements="*"/>

    <xsl:template match="element_in_question">
        <xsl:choose>
            <xsl:when test="preceding-sibling::text() or following-sibling::text()">
                true
            </xsl:when>
            <xsl:otherwise>
                false
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>

生产

false
于 2014-02-06T09:15:05.567 回答