{"id":274,"date":"2012-08-31T14:34:13","date_gmt":"2012-08-31T12:34:13","guid":{"rendered":"http:\/\/xml-tools.com\/xmltribune\/?p=274"},"modified":"2015-10-10T16:02:11","modified_gmt":"2015-10-10T14:02:11","slug":"schematron-check-unique-attributes-elements","status":"publish","type":"post","link":"https:\/\/www.xml-buddy.com\/xmltribune\/schematron-check-unique-attributes-elements\/","title":{"rendered":"Schematron: Check for unique attribute and element values"},"content":{"rendered":"<p>Based on customer feedback I want to post some solutions for two very common Schematron checks. The first rule is an assertion to report if all values of an attribute are unique for all elements (within the same parent). Simply open XML <a href=\"http:\/\/www.xml-buddy.com\/ValidatorBuddy.htm\" >ValidatorBuddy<\/a>, create a new Schematron schema and add the following rule in the editor:<\/p>\n<pre><span style=\"color: #800000;\">&lt;iso:pattern<\/span> <span style=\"color: #0000ff;\">id<\/span>=\"unique name attributes\"<span style=\"color: #800000;\">&gt;<\/span>\r\n<span style=\"color: #800000;\"> &lt;iso:rule<\/span> <span style=\"color: #0000ff;\">context<\/span>=\"people\"<span style=\"color: #800000;\">&gt;<\/span>\r\n    &lt;<span style=\"color: #800000;\">iso:assert<\/span> <span style=\"color: #0000ff;\">test<\/span>=\"count(person) = count(person[not(@name=preceding-sibling::person\/@name)])\"&gt;\r\n      Not all name attributes of the person elements are unique\r\n    &lt;\/<span style=\"color: #800000;\">iso:assert&gt;<\/span>\r\n  <span style=\"color: #800000;\">&lt;\/iso:rule<\/span><span style=\"color: #800000;\">&gt;<\/span>\r\n<span style=\"color: #800000;\">&lt;\/iso:pattern<\/span><span style=\"color: #800000;\">&gt;<\/span><\/pre>\n<p>The second one is a check to see if all element values of a certain element (within the same parent) are unique. Add the following rule and apply it using the built-in Schematron XML validator in XML <a href=\"http:\/\/www.xml-buddy.com\/ValidatorBuddy.htm\" >ValidatorBuddy<\/a>:<\/p>\n<pre><span style=\"color: #800000;\">&lt;iso:pattern<\/span> <span style=\"color: #0000ff;\">id<\/span>=\"unique drawers\"<span style=\"color: #800000;\">&gt;<\/span>\r\n  <span style=\"color: #800000;\">&lt;iso:rule<\/span> <span style=\"color: #0000ff;\">context<\/span>=\"shelf\"<span style=\"color: #800000;\">&gt;<\/span>\r\n    <span style=\"color: #800000;\">&lt;iso:report<\/span> <span style=\"color: #0000ff;\">test<\/span>=\"count(drawer) != count(distinct-values(drawer))\"<span style=\"color: #800000;\">&gt;<\/span>\r\n      Content of drawers not distinct\r\n      <span style=\"color: #800000;\">&lt;iso:value-of<\/span> <span style=\"color: #0000ff;\">select<\/span>=\".\" \/&gt;\r\n    <span style=\"color: #800000;\">&lt;\/iso:report&gt;<\/span>\r\n  <span style=\"color: #800000;\">&lt;\/iso:rule&gt;<\/span>\r\n<span style=\"color: #800000;\">&lt;\/iso:pattern&gt;<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p style=\"opacity:0.5;padding:0;margin:0;display:inline;\"><sub><a href=\"#\" onclick=\"window.open('https:\/\/www.janhvizdak.com\/rdr.me.1'); return false;\" target=\"_blank\" style=\"cursor:help;\"><b>&#187;crosslinked&#171;<\/b><\/a><\/sub><\/p>","protected":false},"excerpt":{"rendered":"<p>Based on customer feedback I want to post some solutions for two very common Schematron checks. The first rule is an assertion to report if all values of an attribute are unique for all elements (within the same parent). Simply open XML ValidatorBuddy, create a new Schematron schema and add the following rule in the editor: &lt;iso:pattern id=&#8221;unique name attributes&#8221;&gt;&#8230; <a href=\"https:\/\/www.xml-buddy.com\/xmltribune\/schematron-check-unique-attributes-elements\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[12,6],"tags":[23,69,74],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/posts\/274"}],"collection":[{"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/comments?post=274"}],"version-history":[{"count":2,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"predecessor-version":[{"id":484,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/posts\/274\/revisions\/484"}],"wp:attachment":[{"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xml-buddy.com\/xmltribune\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}