[Schematron] Help!! Can Schematron do this??
Walsh, Catherine
cwalsh at mitre.org
Wed Jan 28 15:11:11 EST 2009
Hello,
I am working to validate an instance folder against a taxonomy file (has a different namespace than the instance files).
I believe this is possible w/ Schematron, and I believe I'm very close to making it happen.
I am hoping to find help for understanding why the following isn't working:
(PROBLEM: It returns ALL 'code' values found in instance files, even when the value does NOT have a matching id value in the taxonomy file.)
<!-- Declare variable -->
<iso:let name="owl" value="document('../BetaPhase/BETA-TIGER-TEAMS/RelTax-TIGER-TEAM/Ontology/UCoreTaxonomy.owl')"/>
<iso:let name="code" value="*[ucore:code]"/>
<iso:let name="id" value="*[rdf:ID]"/>
<iso:pattern id="code" see="$owl" >
<iso:rule id="validateCode" context="*[@code]">
<iso:assert test="$code = $id" diagnostics="code.diag">
CODE values must conform to the taxonomy file.
</iso:assert>
</iso:rule>
</iso:pattern>
Any suggestions are appreciated!
Thanks,
Kate Walsh
967-8007
cwalsh at mitre.org<mailto:cwalsh at mitre.org>
:: :: ::
From: schematron-bounces at eccnet.com [mailto:schematron-bounces at eccnet.com] On Behalf Of Jingdong Li
Sent: Sunday, January 25, 2009 8:18 AM
To: David Carlisle
Cc: schematron at eccnet.com
Subject: Re: [Schematron] How to check uniqueness of an xml element
Thanks David.
On Mon, Jan 5, 2009 at 2:27 PM, David Carlisle <d.p.carlisle at googlemail.com<mailto:d.p.carlisle at googlemail.com>> wrote:
2009/1/5 Jingdong Li <jingdong.li<http://jingdong.li>@gmail.com<http://gmail.com>>
Greeting,
For following sample file, I'd like to assert that element <a> can only have unique @id.
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="">
<a id="x"/>
<a id="y"/>
<a id="y"/> ---- trigger schematron assert error: "Id not unique!"
</root>
I have following schematron code suppose to do the job:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.ascc.net/xml/schematron">
<pattern name="Element 'a' must have unique 'id' attribute">
<rule context="root/a/@id">
<assert test="count(//@id[. = current()]) = 1"> Id not unique! </assert>
</rule>
</pattern>
</schema>
But everytime I execute the Sch code, it produces following warning:
--> Description: [Schematron 1.5 (XSLT 2.0)] The child axis starting at an attribute node will never select anything.
Could you point out what the proper way is? Thanks in advance.
It's not actually an error, the xslt generated from the schematron 1.5 applies templates to all child nodes, and if the context is an attribute this can never actually have any affect. saxon9, by default, warns of this (as in hand written code it normally indicates a coding error). In simple cases the schematron skeleton can be changed to detect that the context is an attribute node, but in general this can be quite hard an requires a full analysis of the context pattern, which is hard to do in xslt alone.
So you could ignore the warning, or use a command line option to turn warnings off, or avoid it by arranging the context node to be an element, eg
<rule context="root/a">
<assert test="count(//@id[. = current()/@id]) = 1"> Id not unique! </assert>
--
Jingdong(JD) Li
jingdong.li<http://jingdong.li>@gmail.com<http://gmail.com>
David
--
http://dpcarlisle.blogspot.com/
--
Jingdong(JD) Li
jingdong.li<http://jingdong.li>@gmail.com<http://gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eccnet.com/pipermail/schematron/attachments/20090128/f9a07bf8/attachment.html
More information about the Schematron
mailing list