[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
Re: [xml-dev] Generating New Knowledge by Deductive Reasoning using Schematron
- From: Stephen Green <stephengreenubl@gmail.com>
- To: rjelliffe <rjelliffe@allette.com.au>
- Date: Mon, 22 Nov 2010 12:34:41 +0000
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)">
<RobberyEvent>
<datetime><sch:value-of
select="doc('Robbery.xml')/RobberyEvent/datetime"/></datetime>
<description><sch:value-of
select="doc('Robbery.xml')/RobberyEvent/description"/></description>
<evidence>
<Gun>
<serial><sch:value-of
select="doc('Robbery.xml')/RobberyEvent/evidence/Gun/serial"/></serial>
</Gun>
</evidence>
<robber>
<Person> <sch:value-of
select="parent::Person/child::name"/> </Person>
</robber>
</RobberyEvent>
</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>
<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>
</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]