Tecnologías XML / Schematron / SVRL / Estructura
(Extracto de "Schematron - Effiziente Business Rules für XML-Dokumente", capítulo 9)
Los errores pueden describirse con precisión porque SVRL representa información útil además de los propios mensajes.
El anexo D del estándar ISO de Schematron describe SVRL mediante un esquema RELAX NG. Los ejemplos anteriores mostraban la salida final en XTHML o texto sin formato. Este es un ejemplo:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<title>Schematron für Noah</title>
<p>Dieses Schematron soll Noah helfen, die richtigen Tiere in der adäquaten Umgebung unterzubringen.</p>
<ns uri="http://www.schematron.info/arche" prefix="arc"/>
<phase id="alles">
<active pattern="arche"/>
<active pattern="noah"/>
</phase>
<pattern id="arche">
<rule context="arc:zimmer[arc:tier[@fleischfresser='nein']]">
<report test="arc:tier[@fleischfresser='ja']">Es gibt Fleischfresser und Pflanzenfresser in einer Unterkunft. Die Tiere sind keine Nahrungsquelle!</report>
</rule>
</pattern>
<pattern id="noah">
<rule context="arc:tier">
<let name="tierart" value="arc:art"/>
<report test="count(parent::*/arc:tier[arc:art=$tierart]) > 2" diagnostics="Anzahl">In dieser Unterkunft gibt es mehr als zwei Tiere dieser Art (<value-of select="arc:art"/>).</report>
<assert test="not(count(parent::*/arc:tier[arc:art=$tierart]) < 2)">In dieser Unterkunft gibt es kein Paar dieser Art (<value-of select="arc:art"/>).</assert>
</rule>
</pattern>
<diagnostics>
<diagnostic id="Anzahl">Noah, du hast <value-of select="count(parent::*/arc:tier[arc:art=$tierart])"/> Tiere von der Gattung <value-of select="arc:art"/>.</diagnostic>
</diagnostics>
</schema>Este es el archivo SVRL resultante:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svrl:schematron-output xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:iso="http://purl.oclc.org/dsdl/schematron" xmlns:arc="http://www.schematron.info/arche" xmlns:svrl="http://purl.oclc.org/dsdl/svrl" title="Schematron für Noah" schemaVersion="">
<svrl:text>Dieses Schematron soll Noah helfen, die richtigen Tiere in der adäquaten Umgebung unterzubringen.</svrl:text>
<svrl:ns-prefix-in-attribute-values uri="http://www.schematron.info/arche" prefix="arc"/>
<svrl:active-pattern id="arche" name="arche"/>
<svrl:fired-rule context="arc:zimmer[arc:tier[@fleischfresser='nein']]"/>
<svrl:successful-report test="arc:tier[@fleischfresser='ja']" location="/*:arche[namespace-uri()='http://www.schematron.info/arche'][1]/*:ladung[namespace-uri()='http://www.schematron.info/arche'][1]/*:zimmer[namespace-uri()='http://www.schematron.info/arche'][1]">
<svrl:text>Es gibt Fleischfresser und Pflanzenfresser in einer Unterkunft. Die Tiere sind keine Nahrungsquelle!</svrl:text>
</svrl:successful-report>
<svrl:fired-rule context="arc:zimmer[arc:tier[@fleischfresser='nein']]"/>
<svrl:active-pattern id="noah" name="noah"/>
<svrl:fired-rule context="arc:tier"/>
<svrl:successful-report test="count(parent::*/arc:tier[arc:art=$tierart]) > 2" location="/*:arche[namespace-uri()='http://www.schematron.info/arche'][1]/*:ladung[namespace-uri()='http://www.schematron.info/arche'][1]/*:zimmer[namespace-uri()='http://www.schematron.info/arche'][1]/*:tier[namespace-uri()='http://www.schematron.info/arche'][1]">
<svrl:text>In dieser Unterkunft gibt es mehr als zwei Tiere dieser Art (Zebra). <svrl:diagnostic-reference diagnostic="Anzahl" id="Anzahl">Noah, du hast 3 Tiere von der Gattung Zebra.</svrl:diagnostic-reference></svrl:text>
</svrl:successful-report>
…
<svrl:fired-rule context="arc:tier"/>
<svrl:fired-rule context="arc:tier"/>
</svrl:schematron-output>El elemento raíz de un documento SVRL es <svrl:schematron-output>. Hay tres atributos disponibles. El atributo title puede contener el texto del elemento Schematron <title>. El atributo phase todavía no tiene un uso definido con precisión, pero probablemente contendría el nombre del elemento seleccionado <phase>. El atributo schemaVersion toma el valor del atributo homónimo del elemento raíz Schematron <schema>.
También existen los elementos opcionales <svrl:text> y <svrl:ns-prefix-in-attribute-values>. <svrl:text> contiene el contenido de <p>; <svrl:ns-prefix-in-attribute-values> corresponde al elemento Schematron <ns>.
Así,
<ns uri="http://www.schematron.info/arche" prefix="arc"/>se convierte en lo siguiente en SVRL:
<svrl:ns-prefix-in-attribute-values uri="http://www.schematron.info/arche" prefix="arc"/>El elemento <svrl:active-pattern> indica los patterns activos en esta fase.
Se evalúa el elemento <active>. Los dos atributos id y name reciben el valor del atributo pattern de <active>. Todos los elementos <svrl:fired-rule> siguientes hasta el próximo <svrl:active-pattern> pertenecen a este grupo. Si no se utilizó <active>, <svrl:active-pattern> se genera sin atributos porque es obligatorio.
El elemento central <svrl:fired-rule> se genera cada vez que se cumple una regla. En nuestra arca sucede cuando se cumple el atributo context del elemento <rule>.
<rule context="arc:zimmer[arc:tier[@fleischfresser='nein']]">El elemento <svrl:fired-rule> también tiene un atributo context, al que se copia el contenido del atributo <rule>-context, como se muestra aquí:
<svrl:fired-rule context="arc:zimmer[arc:tier[@fleischfresser='nein']]"/>Los elementos <svrl:failed-assert> y <svrl:successful-report> se generan cuando el elemento <assert> o <report> se activa, respectivamente. Ambos tienen el atributo test, que muestra la expresión XPath, según se utilice <assert> o <report>, y copia el contenido de los atributos test. El atributo location contiene la posición exacta de la aserción o mensaje, preferiblemente como expresión XPath absoluta.
Este es un ejemplo:
<svrl:successful-report test="arc:tier[@fleischfresser='ja']" location="/*:arche[namespace-uri()='http://www.schematron.info/arche'][1]/*:ladung[namespace-uri()='http://www.schematron.info/arche'][1]/*:zimmer[namespace-uri()='http://www.schematron.info/arche'][1]">Dentro de <svrl:failed-assert> y <svrl:successful-report>, los textos descriptivos procedentes de <assert> o <report> se generan en un <svrl:text>.
<svrl:failed-assert test="not(count(parent::*/arc:tier[arc:art=$tierart]) < 2)" location="/*:arche[namespace-uri()='http://www.schematron.info/arche'][1]/*:ladung[namespace-uri()='http://www.schematron.info/arche'][1]/*:zimmer[namespace-uri()='http://www.schematron.info/arche'][1]/*:tier[namespace-uri()='http://www.schematron.info/arche'][4]">
<svrl:text>In dieser Unterkunft gibt es kein Paar dieser Art (Zebra).</svrl:text>
</svrl:failed-assert>
El elemento <svrl:diagnostic-reference> contiene el contenido de <diagnostic>, referenciado mediante un identificador en Schematron.
Este es un ejemplo:
<svrl:diagnostic-reference diagnostic="Anzahl" id="Anzahl">Noah, du hast 3 Tiere von der Gattung Zebra.</svrl:diagnostic-reference>Como este contenido depende de <assert> o <report> , aquí se muestra el texto y los elementos <value-of> que existan se resuelven.
Copyright © dpunkt.verlag GmbH 2011
Puede imprimir la versión en línea para uso privado. Por lo demás, este capítulo de "Schematron - Effiziente Business Rules für XML-Dokumente" se rige por las mismas condiciones que la edición impresa: la obra y todas sus partes están protegidas por derechos de autor. Se reservan todos los derechos, incluidos reproducción, traducción, microfilmación, almacenamiento y procesamiento en sistemas electrónicos.
dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, tel. 06221-14830, fax 06221-148399, hallo(at)dpunkt.de
volver arriba