Schematron: Element within mixed-type element only with other content

My XML Data should look like this:

<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>

What I want to make sure using Schematron is that the "element_in_question" may only appear within "mixed_type_parent" if there is some text outside of the "element_in_question". That means

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

is not allowed and should cause an error.

I tried to get the string-length of all text immediately within "mixed_type_parent"

string-length(replace(ancestor::mixed_type_parent[1]/text(),' ', ''))

But, again, there is one of the most annoying errors in XPath: "A sequence of more than one item is not allowed as the first argument of replace()"

In XSLT I have solved this problem by the simplest function you can think about:

<xsl:function name="locfun:make_string">
 <xsl:param name="input_sequence"/>
 <xsl:value-of select="$input_sequence"/>
</xsl:function>

(It is really a shame that there seams to be no such built-in function in XPath.)

But how can I use this function in Schematron? I didn't find a solution for this.

And other than that: How do I get all text form all other childs of "mixed_type_parent" except "mixed_type_parent"?

Answers


Try this:

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

For your second question: How do I get all text form all other childs of "mixed_type_parent" except "mixed_type_parent"?

/mixed_type_parent/*[not(self::element_in_question)]/text()

considering this input XML,

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

when this XSLT is applied:

<?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>

produces

false

Need Your Help

Unable to authenticate with Twitter using Twitter4j on Android

android twitter twitter4j

So, I'm getting a 'No authentication challenges found' error when trying to authenticate through Twitter. And before you ask, yes, I've googled the issue; there were only three pages of results, an...

<MailSettings> Use deliveryMethods 'Network' and 'SpecifiedPickupDirectory' simultaneously

asp.net .net email smtpclient configurationmanager

Exactly as it says on the tin: is it possible to specify both delivery methods in a single configuration? I'd figure it'd be a quick (and cheap) solution to log all e-mail messages that were sent