Page 1 of 1

Schermatron: matching element element content with other element name

Posted: Tue May 09, 2017 5:19 pm
by Iwicka
Hi,

I have the following XML document:

Code: Select all

<abc:root xmlns:abc="urn:xyz:abc" xmlns:hij="urn:xyz:def">
<element1>SomeName</element1>
<element2>
<element3>SomeText</element3>
<hij:element4>
<someMoreElements/>
</hij:element4>
</element2>
</abc:root>
and need to write a schematron assertion testing that the text in element1: SmomeName matches the tag name of element4, without the namespace prefix. The SomeText and element tag name are different in every document.
I figured out that I need to point to the 2nd child of <element2> and probably use the NCName, but I have no idea how to put it all together.
Alternatively, I could point to the sibling of <element3>, which is always the same, but still I don't knoiw how to get the name of <element4>. None of the variants I tried worked so far.

Every help will be appreciated.

Ewa

Re: Schermatron: matching element element content with other element name

Posted: Wed May 10, 2017 8:43 am
by tavy
Hello,

For the example that you provided You need to create a Schematron something like this:

Code: Select all


<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<sch:pattern>
<sch:rule context="element1">
<sch:let name="matchElemName" value="following-sibling::*[1]/child::*[2]/local-name()"/>
<sch:assert test="text() = $matchElemName">
The name of the elemnt must be '<sch:value-of select="text()"/>', but is '<sch:value-of select="$matchElemName"/>'
</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
Best Regards,
Octavian