[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Generating New Knowledge by Deductive Reasoning using Sche

  • From: Stephen Green <stephengreenubl@gmail.com>
  • To: rjelliffe <rjelliffe@allette.com.au>
  • Date: Mon, 22 Nov 2010 12:34:41 +0000

Re:  Generating New Knowledge by Deductive Reasoning using Sche
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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.