Re: Checking/Reporting on Many Nodes

"Edvard Robertsson" <[email protected]> Wed, 02 Jun 2004 15:42:06 +0200
Newsgroups gmane.text.xml.schematron
Message-ID <[email protected]>
This is a multi-part message in MIME format.

------=_NextPart_000_2c56_3727_46f8
Content-Type: text/plain; format=flowed

Hi Noah,

>It depends on the version of Schematron you use. The schematron-report tool 
>at the Academia Sinica site has a two pane view that links to the error. 
>This is also available in the free Schematron validator for Windows at
>http://www.topologi.com

Another option if you don't use the schematron-report tool would be to use 
the diagnostics function in Schematron. For example the following snippet of 
a Schematron schema:

<sch:pattern name="Test">
    <sch:rule context="Product">
        <sch:assert test="CCC" diagnostics="d1">Products must have a CCC 
element.</sch:assert>
    </sch:rule>
</sch:pattern>
<sch:diagnostics>
    <sch:diagnostic id="d1">(REF = <sch:value-of 
select="REF"/>)</sch:diagnostic>
</sch:diagnostics>

will produce this output for the snippet you posted below:

From pattern "Test":
     Assertion fails: "Products must have a CCC element."  at
         /Message[1]/Product[1]
        <Product>...</> (REF = 1 )

The diagnostics message is displayed last in the reported message (REF = 1) 
which displays the REF value of the product that failed.

Note that the default schematron-basic.xsl implementation doesn't support 
diagnostics but I've attached a modified stylesheet that basically is the 
same as schematron-basic.xsl but with support for diagnostics.

Cheers,
/Eddie

>>I'm new to Schematron (glad I found it!) and I'm a little stuck. Here's 
>>the
>>deal...I have a document that I'm checking that looks like this:
>>
>><Message>
>><Product>
>>   <REF>1</REF>
>>   <AAA>Test1</AAA>
>>   <BBB>Test1</BBB>
>></Product>
>><Product>
>>   <REF>2</REF>
>>   <AAA>Test2</AAA>
>>   <BBB>Test2</BBB>
>>   <CCC>Test2</CCC>
>></Product>
>></Message>
>>
>>I'm checking for the presence of some elements, attributes and some data
>>checking and that seems to work fine. However, my document can contain a 
>>lot of
>><Product> nodes (thousands) and when one of checks fails I would like to 
>>know
>>which <Product> node had the error. I'm pretty sure I can reference the 
>><REF>
>>element (which is unique) in some manner to give me the 'location' of the 
>>error,
>>but I'm stumped as to how to do that. Right now my schema 'tests' the 
>>document
>>and gives me a list of errors, but not where those errors are.
>>
>>Any help is appreciated,
>>
>>
>>
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: Oracle 10g
>Get certified on the hottest thing ever to hit the market... Oracle 10g. 
>Take an Oracle 10g class now, and we'll give you the exam FREE.
>http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
>_______________________________________________
>Schematron-love-in mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/schematron-love-in

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

------=_NextPart_000_2c56_3727_46f8
Content-Type: text/xml; name="schematron-diagnose.xsl"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="schematron-diagnose.xsl"

<?xml version="1.0" ?>
<!-- Basic metastylesheet for the Schematron XML Schema Language.
	http://www.ascc.net/xml/resource/schematron/schematron.html

 Copyright (c) 2000,2001 Rick Jelliffe and Academia Sinica Computing Center, Taiwan

 This software is provided 'as-is', without any express or implied warranty. 
 In no event will the authors be held liable for any damages arising from 
 the use of this software.

 Permission is granted to anyone to use this software for any purpose, 
 including commercial applications, and to alter it and redistribute it freely,
 subject to the following restrictions:

 1. The origin of this software must not be misrepresented; you must not claim
 that you wrote the original software. If you use this software in a product, 
 an acknowledgment in the product documentation would be appreciated but is 
 not required.

 2. Altered source versions must be plainly marked as such, and must not be 
 misrepresented as being the original software.

 3. This notice may not be removed or altered from any source distribution.
-->

<!-- Schematron diagnose -->

<xsl:stylesheet
   version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias">

<xsl:import href="skeleton1-5.xsl"/>
<xsl:param name="diagnose">yes</xsl:param>

<xsl:template name="process-prolog">
   <axsl:output method="text" />
</xsl:template>

<xsl:template name="process-root">
   <xsl:param name="title" />
   <xsl:param name="contents" />
   <xsl:value-of select="$title" />
   <xsl:text>&#10;</xsl:text>
   <xsl:copy-of select="$contents" />
</xsl:template>

<xsl:template name="process-pattern">
	<xsl:param name="name" />
	<xsl:text>&#10;</xsl:text>
	<xsl:text>&#10;</xsl:text>
        <xsl:text>From pattern "</xsl:text>
        <xsl:value-of select="$name" />
	<xsl:text>": </xsl:text>
</xsl:template>

<xsl:template name="process-assert">
	<xsl:param name="test" />
	<xsl:param name="role" />
	<xsl:param name="diagnostics" />
	
	<xsl:text>&#10;</xsl:text>
	<xsl:text>     Assertion fails: </xsl:text>
	<xsl:call-template name="process-message">
		<xsl:with-param name="pattern" select="$test"/>
		<xsl:with-param name="role" select="$role"/>
	</xsl:call-template>
	<xsl:text> </xsl:text>
	<xsl:if test="$diagnose = 'yes'">
		<xsl:call-template name="diagnosticsSplit">
             		<xsl:with-param name="str" select="$diagnostics"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>

<xsl:template name="process-report">
	<xsl:param name="test" />
	<xsl:param name="role" />
	<xsl:param name="diagnostics"/>

	<xsl:text>&#10;</xsl:text>
	<xsl:text>      Report: </xsl:text>
	<xsl:call-template name="process-message">
		<xsl:with-param name="pattern" select="$test"/>
		<xsl:with-param name="role" select="$role"/>
	</xsl:call-template>
	<xsl:text> </xsl:text>
	<xsl:if test="$diagnose = 'yes'">
		<xsl:call-template name="diagnosticsSplit">
             		<xsl:with-param name="str" select="$diagnostics"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>


<xsl:template name="process-message">
   <xsl:param name="pattern" />
   <xsl:param name="role" />
   <xsl:if test="$role">
      <xsl:text> (</xsl:text>
      <xsl:value-of select="$role" />
      <xsl:text>)</xsl:text>
   </xsl:if>"<xsl:apply-templates mode="text" />"  at 
         <axsl:apply-templates mode="schematron-get-full-path" select="." /> 
        &lt;<axsl:value-of select="name()"/><axsl:for-each select="@*"
		><axsl:value-of select="' '"/><axsl:value-of select="name()"
		/>="<axsl:value-of select="."/>"</axsl:for-each>&gt;...&lt;/&gt;</xsl:template>
     

</xsl:stylesheet>


------=_NextPart_000_2c56_3727_46f8--


-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504