0

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

cis
  • 1,259
  • 15
  • 48

2 Answers2

2

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()
Tobias Klevenz
  • 1,625
  • 11
  • 13
  • Sometimes I don't understand XPath. I tried concat() because it is more convenient and got an error. But string-join() works. I simply don't get why it is this way. But thank you very much! – cis Feb 06 '14 at 15:08
  • well concat expects multiple arguments that each represent a string, so you'd have to know the number of strings you'll want to concat before hand, while string-join expects a sequence of strings and a separator and than basically does like a looped concat for you. – Tobias Klevenz Feb 06 '14 at 17:26
0

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
Joel M. Lamsen
  • 7,143
  • 1
  • 12
  • 14