XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Generating New Knowledge by Deductive Reasoning using Schematron

I tried SVRL where I had the Schematron schema output escaped XML
(conforming to the Robber.xml markup in Roger's example but escaped)
in the 'text' of the report. The escaped XML ends up in the SVRL svrl:text
element which is fine because I can then run a second transformation to
convert the escaped content of this element to unescaped XML.

So I ran the Schematron schema against the input file using an XSLT2
Schematron SVRL-output stylesheet (iso_svrl_for_xslt2.xsl).

This is the Schematron schema I used which includes the report XML
escaped as text in the sch:report:

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron";
xmlns:xs="http://www.w3.org/2001/XMLSchema"; queryBinding="xslt2">
	<sch:pattern id="Check-Speeder-For-Relationship-To-Recent-Events">
		<sch:rule context="driversLicenseNumber">
			<sch:let name="speeder-driversLicenseNumber" value="."/>
			<sch:let name="GunLicense" value="for $i in
collection('GunLicenseFolder?select=*.xml;recurse=yes;on-error=ignore')
                                           return
$i/GunLicense[.//Person/driversLicenseNumber eq
$speeder-driversLicenseNumber]"/>
			<sch:report test="($speeder-driversLicenseNumber eq
$GunLicense//Person/driversLicenseNumber) and
            ($GunLicense/registeredGun/Gun/serial eq
doc('Robbery.xml')/RobberyEvent/evidence/Gun/serial) and
            (count($GunLicense) eq 1) and
            (count($GunLicense//Person) eq 1)">
           &lt;RobberyEvent&gt;
           &lt;datetime&gt;<sch:value-of
select="doc('Robbery.xml')/RobberyEvent/datetime"/>&lt;/datetime&gt;
           &lt;description&gt;<sch:value-of
select="doc('Robbery.xml')/RobberyEvent/description"/>&lt;/description&gt;
           &lt;evidence&gt;
           &lt;Gun&gt;
           &lt;serial&gt;<sch:value-of
select="doc('Robbery.xml')/RobberyEvent/evidence/Gun/serial"/>&lt;/serial&gt;
           &lt;/Gun&gt;
           &lt;/evidence&gt;
           &lt;robber&gt;
           &lt;Person&gt; <sch:value-of
select="parent::Person/child::name"/> &lt;/Person&gt;
           &lt;/robber&gt;
           &lt;/RobberyEvent&gt;
         </sch:report>
		</sch:rule>
	</sch:pattern>
</sch:schema>

The resulting SVRL output looks something like this:

<svrl:schematron-output
xmlns:schold="http://www.ascc.net/xml/schematron";
xmlns:iso="http://purl.oclc.org/dsdl/schematron";
xmlns:saxon="http://saxon.sf.net/";
xmlns:svrl="http://purl.oclc.org/dsdl/svrl";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:xhtml="http://www.w3.org/1999/xhtml";
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; title=""
schemaVersion="">
	<svrl:active-pattern document="file:/..../Speeder.xml"
id="Check-Speeder-For-Relationship-To-Recent-Events"
name="Check-Speeder-For-Relationship-To-Recent-Events"/>
	<svrl:fired-rule context="driversLicenseNumber"/>
	<svrl:successful-report test="($speeder-driversLicenseNumber eq
$GunLicense//Person/driversLicenseNumber) and
($GunLicense/registeredGun/Gun/serial eq
doc('Robbery.xml')/RobberyEvent/evidence/Gun/serial) and
(count($GunLicense) eq 1) and (count($GunLicense//Person) eq 1)"
location="/SpeedingOffense[1]/speeder[1]/Person[1]/driversLicenseNumber[1]">
		<svrl:text>
           &lt;RobberyEvent&gt;
           &lt;datetime&gt;2010-11-16T0500-00-00&lt;/datetime&gt;
           &lt;description&gt;Robbery occurred, gun was dropped while
fleeing&lt;/description&gt;
           &lt;evidence&gt;
           &lt;Gun&gt;
           &lt;serial&gt;ABCD&lt;/serial&gt;
           &lt;/Gun&gt;
           &lt;/evidence&gt;
           &lt;robber&gt;
           &lt;Person&gt; Fred Blogs &lt;/Person&gt;
           &lt;/robber&gt;
           &lt;/RobberyEvent&gt;
         </svrl:text>
	</svrl:successful-report>
</svrl:schematron-output>

I transform it again with a second step with this simple stylesheet:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:schold="http://www.ascc.net/xml/schematron";
xmlns:iso="http://purl.oclc.org/dsdl/schematron";
xmlns:saxon="http://saxon.sf.net/";
xmlns:svrl="http://purl.oclc.org/dsdl/svrl";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:xhtml="http://www.w3.org/1999/xhtml";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
	<xsl:output method="xml" version="1.0" indent="yes" encoding="UTF-8"/>
	<xsl:template match="/">
		<xsl:apply-templates
select="svrl:schematron-output/svrl:successful-report/svrl:text" />
	</xsl:template>
	<xsl:template match="svrl:schematron-output/svrl:successful-report/svrl:text">
		<xsl:value-of select="." disable-output-escaping="yes"/>
	</xsl:template>		
</xsl:stylesheet>

This produces the desired unescaped XML:

<RobberyEvent>
	<datetime>2010-11-16T0500-00-00</datetime>
	<description>Robbery occurred, gun was dropped while fleeing</description>
	<evidence>
		<Gun>
			<serial>ABCD</serial>
		</Gun>
	</evidence>
	<robber>
		<Person> Fred Blogs </Person>
	</robber>
</RobberyEvent>


which can then become input for further Schematron processes / deductions.

Cool. I wouldn't say the SVRL adds a lot in this particular scenario (not the
usual Schematron scenario of XML validation, admitedly) but it helps to get
XML output as a precursor to XSLT transformation to unescape the text as
the final XML output.


Best regards

Steve
---
Stephen D Green


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS