newbie to Schematron - help!
Posted: Wed Nov 14, 2007 5:28 pm
Hi
I am trying to use schematron to validate an xml file that looks something like this
<top>
<Marker>
<MarkerID>1</MarkerID>
<VariationType>test</VariationType>
<Source>dbtest</Source>
<LocalID>rs699</LocalID>
</Marker>
<Marker>
<MarkerID>2</MarkerID>
<VariationType>test</VariationType>
<Source>dbtest</Source>
<LocalID>rs698</LocalID>
</Marker>
<Marker>
<MarkerID>3</MarkerID>
<VariationType>test</VariationType>
<Source>dbtest</Source>
<LocalID>rs699</LocalID>
</Marker>
</top>
I need to be able to say if an rs number (e.g rs699 but its not always this!) (<LocalID>) occurs more than once in an xml document
so far after digging around i have managed to come up with this
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern fpi="LocalID">
<rule context="/top/Marker/LocalID">
<assert test="not(count(preceding-sibling::LocalID[.=current()]) = 1)">
Duplicate <value-of select ="."/>
key exists <value-of select="count(../LocalID[.=current()])"/> times.
Keys should be unique.
</assert>
</rule>
</pattern>
</schema>
which works but only it if the <LocalID> appears one or more times in a <Marker> block which is not what i want.
Any help / suggestions welcome as i am new to schematron
Thanks
Rob
I am trying to use schematron to validate an xml file that looks something like this
<top>
<Marker>
<MarkerID>1</MarkerID>
<VariationType>test</VariationType>
<Source>dbtest</Source>
<LocalID>rs699</LocalID>
</Marker>
<Marker>
<MarkerID>2</MarkerID>
<VariationType>test</VariationType>
<Source>dbtest</Source>
<LocalID>rs698</LocalID>
</Marker>
<Marker>
<MarkerID>3</MarkerID>
<VariationType>test</VariationType>
<Source>dbtest</Source>
<LocalID>rs699</LocalID>
</Marker>
</top>
I need to be able to say if an rs number (e.g rs699 but its not always this!) (<LocalID>) occurs more than once in an xml document
so far after digging around i have managed to come up with this
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern fpi="LocalID">
<rule context="/top/Marker/LocalID">
<assert test="not(count(preceding-sibling::LocalID[.=current()]) = 1)">
Duplicate <value-of select ="."/>
key exists <value-of select="count(../LocalID[.=current()])"/> times.
Keys should be unique.
</assert>
</rule>
</pattern>
</schema>
which works but only it if the <LocalID> appears one or more times in a <Marker> block which is not what i want.
Any help / suggestions welcome as i am new to schematron
Thanks
Rob