saxon:validate - how to use?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

saxon:validate - how to use?

Rob Koberg-2
I need to validate a large number of mathml instances that exist inside of (x)html files. Each html file can have multiple instances of mathml. After purchasing  Saxon EE, I want to use the saxon:validate extension, but not really clear on how to do that.

The documentation for the validate extension says the function returns a map. How do you work with this map? Am I using the mathml schema just by importing it? Is there an example XSL that does this type of thing that I can just copy from :)

Basically I want to create a report of all validation errors listing the document the error was found, the error message(s), and the mathml instance. Here is what I have so far:

<xsl:stylesheet
  version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xpath-default-namespace="http://www.w3.org/1999/xhtml"
  xmlns:mathml="http://www.w3.org/1998/Math/MathML"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map">
 
 
<!--
  Command line transform:
 
  $ export CLASSPATH=$CLASSPATH:tagsoup-1.2.1.jar
  $ java net.sf.saxon.Transform -o:validation.html -s:conf.xml -xsl:math-validation.xsl -x:org.ccil.cowan.tagsoup.Parser
 
  Requires both saxon and tagsoup in the classpath
  -->
 
<xsl:import-schema namespace="http://www.w3.org/1998/Math/MathML" schema-location="mathml2/mathml2.xsd"/>
 
 
<xsl:template match="/conf">
   
<html>
     
<head>
       
<title>MathML Validation Report</title>
     
</head>
     
<body>
       
<table>
         
<tr>
           
<th>Filename</th>
           
<th>Validation</th>
           
<th>MathML</th>
         
</tr>
         
<xsl:apply-templates select="collection(concat('./G08', '?select=*.xhtml;recurse=yes'))/*" mode="validate"/>
         
<xsl:apply-templates select="collection(concat('./G08', '?select=*.html;recurse=yes'))/*" mode="validate"/>
         
       
</table>
     
</body>
   
</html>
 
</xsl:template>
 
 
<xsl:template match="*" mode="validate"/>
 
 
<xsl:template match="/*" mode="validate">
   
   
<xsl:apply-templates select="//math" mode="validate"/>
   
 
</xsl:template>
 
 
<xsl:template match="math" mode="validate" priority="10">
   
<xsl:variable name="validation" select="saxon:validate(.)"/>
   
   
<xsl:if test="map:get($validation, 'valid') = false()">
     
     
<tr>
       
<td>
         
<xsl:value-of select="substring-after(document-uri(/), 'file:/Users/rkoberg/Documents/psoc-math/')"/>
       
</td>
       
<td>
         
<xsl:apply-templates select="map:get($validation, 'errors')" mode="message"/>
       
</td>
       
<td>
         
<xsl:apply-templates select="." mode="copy-math"/>
       
</td>
     
</tr>
     
   
</xsl:if>
 
</xsl:template>
 
 
<xsl:template match="element()" mode="copy-math" priority="5">
   
<xsl:element name="{local-name()}" namespace="http://www.w3.org/1998/Math/MathML">
     
<xsl:apply-templates select="@*|node()" mode="copy-math"/>
   
</xsl:element>
 
</xsl:template>
 
 
<xsl:template match="@*|node()" mode="copy-math">
   
<xsl:copy>
     
<xsl:apply-templates select="@*|node()" mode="copy-math"/>
   
</xsl:copy>
 
</xsl:template>
 
 
<xsl:template match="@*|node()" mode="message">
   
<xsl:copy>
     
<xsl:apply-templates select="@*|node()" mode="message"/>
   
</xsl:copy>
 
</xsl:template>
 
</xsl:stylesheet>


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: saxon:validate - how to use?

Rob Koberg-2
I was able to get this to work. The main problem was that I was not using XSL 3.0 and the mathml I was trying to validate was not in the mathml namespace. Here is what worked:

<xsl:stylesheet
  version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xpath-default-namespace="http://www.w3.org/1999/xhtml"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:mathml="http://www.w3.org/1998/Math/MathML"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map"
  xmlns:f="http://my-functions">
 
 
<!--
  Command line transform:
 
  $ export CLASSPATH=$CLASSPATH:tagsoup-1.2.1.jar
  $ java net.sf.saxon.Transform -o:validation.html -s:conf.xml -xsl:math-validation.xsl -x:org.ccil.cowan.tagsoup.Parser
 
  Requires both saxon and tagsoup in the classpath
  -->
 
<xsl:import-schema namespace="http://www.w3.org/1998/Math/MathML" schema-location="mathml2/mathml2.xsd"/>
 
 
<xsl:template match="/conf">
   
<html>
     
<head>
       
<title>MathML Validation Report</title>
     
</head>
     
<body>
       
<table border="1">
         
<tr>
           
<th>Filename</th>
           
<th>Validation</th>
           
<th>MathML</th>
         
</tr>
         
         
<xsl:apply-templates select="collection(concat('.', '?select=*.xhtml;recurse=yes'))/*" mode="validate"/>
         
<xsl:apply-templates select="collection(concat('.', '?select=*.html;recurse=yes'))/*" mode="validate"/>
         
       
</table>
     
</body>
   
</html>
 
</xsl:template>
 
 
<xsl:template match="*" mode="validate"/>
 
 
<xsl:template match="/*" mode="validate">
   
   
<xsl:apply-templates select="//math" mode="validate"/>
   
 
</xsl:template>
 
 
<xsl:template match="math" mode="validate" priority="10">
   
<xsl:variable name="mathml-instance">
     
<xsl:apply-templates select="." mode="copy-math"/>
   
</xsl:variable>
   
<xsl:variable name="validation" select="saxon:validate($mathml-instance)"/>
   
   
<xsl:if test="not(map:get($validation, 'valid'))">
     
     
<tr>
       
<td>
         
<xsl:value-of select="substring-after(document-uri(/), 'file:/Users/rkoberg/Documents/psoc-math/')"/>
       
</td>
       
<td>
         
<ul>
           
<xsl:for-each select="map:get($validation, 'errors')">
             
<xsl:variable name="error" select="."/>
             
<li>
               
<xsl:value-of select="$error('message')"/>
             
</li>
           
</xsl:for-each>
         
</ul>
       
</td>
       
<td>
         
<xsl:apply-templates select="." mode="escape-math"/>
       
</td>
     
</tr>
     
   
</xsl:if>
 
</xsl:template>
 
 
<xsl:template match="element()" mode="copy-math" priority="5">
   
<xsl:element name="{local-name()}" namespace="http://www.w3.org/1998/Math/MathML">
     
<xsl:apply-templates select="@*|node()" mode="copy-math"/>
   
</xsl:element>
 
</xsl:template>
 
<xsl:template match="@*|node()" mode="copy-math">
   
<xsl:copy>
     
<xsl:apply-templates select="@*|node()" mode="copy-math"/>
   
</xsl:copy>
 
</xsl:template>
 
 
 
<xsl:template match="element()" mode="escape-math" priority="5">
   
<xsl:text>&lt;</xsl:text>
   
<xsl:value-of select="local-name()"/>
   
<xsl:text>&gt;</xsl:text>
   
<xsl:apply-templates select="@*|node()" mode="escape-math"/>
   
<xsl:text>&lt;/</xsl:text>
   
<xsl:value-of select="local-name()"/>
   
<xsl:text>&gt;</xsl:text>
 
</xsl:template>
 
 
<xsl:template match="@*" mode="escape-math">
   
<xsl:text> </xsl:text>
   
<xsl:value-of select="local-name()"/>
   
<xsl:text>="</xsl:text>
   
<xsl:value-of select="."/>
   
<xsl:text>"</xsl:text>
 
</xsl:template>
 
 
<xsl:template match="node()" mode="escape-math">
   
<xsl:copy>
     
<xsl:apply-templates select="@*|node()" mode="copy-math"/>
   
</xsl:copy>
 
</xsl:template>
 
</xsl:stylesheet>


On Mon, May 4, 2015 at 7:12 AM, Rob Koberg <[hidden email]> wrote:
I need to validate a large number of mathml instances that exist inside of (x)html files. Each html file can have multiple instances of mathml. After purchasing  Saxon EE, I want to use the saxon:validate extension, but not really clear on how to do that.

The documentation for the validate extension says the function returns a map. How do you work with this map? Am I using the mathml schema just by importing it? Is there an example XSL that does this type of thing that I can just copy from :)

Basically I want to create a report of all validation errors listing the document the error was found, the error message(s), and the mathml instance. Here is what I have so far:

<xsl:stylesheet
  version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xpath-default-namespace="http://www.w3.org/1999/xhtml"
  xmlns:mathml="http://www.w3.org/1998/Math/MathML"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map">
 
 
<!--
  Command line transform:
 
  $ export CLASSPATH=$CLASSPATH:tagsoup-1.2.1.jar
  $ java net.sf.saxon.Transform -o:validation.html -s:conf.xml -xsl:math-validation.xsl -x:org.ccil.cowan.tagsoup.Parser
 
  Requires both saxon and tagsoup in the classpath
  -->
 
<xsl:import-schema namespace="http://www.w3.org/1998/Math/MathML" schema-location="mathml2/mathml2.xsd"/>
 
 
<xsl:template match="/conf">
   
<html>
     
<head>
       
<title>MathML Validation Report</title>
     
</head>
     
<body>
       
<table>
         
<tr>
           
<th>Filename</th>
           
<th>Validation</th>
           
<th>MathML</th>
         
</tr>
         
<xsl:apply-templates select="collection(concat('./G08', '?select=*.xhtml;recurse=yes'))/*" mode="validate"/>
         
<xsl:apply-templates select="collection(concat('./G08', '?select=*.html;recurse=yes'))/*" mode="validate"/>
         
       
</table>
     
</body>
   
</html>
 
</xsl:template>
 
 
<xsl:template match="*" mode="validate"/>
 
 
<xsl:template match="/*" mode="validate">
   
   
<xsl:apply-templates select="//math" mode="validate"/>
   
 
</xsl:template>
 
 
<xsl:template match="math" mode="validate" priority="10">
   
<xsl:variable name="validation" select="saxon:validate(.)"/>
   
   
<xsl:if test="map:get($validation, 'valid') = false()">
     
     
<tr>
       
<td>
         
<xsl:value-of select="substring-after(document-uri(/), 'file:/Users/rkoberg/Documents/psoc-math/')"/>
       
</td>
       
<td>
         
<xsl:apply-templates select="map:get($validation, 'errors')" mode="message"/>
       
</td>
       
<td>
         
<xsl:apply-templates select="." mode="copy-math"/>
       
</td>
     
</tr>
     
   
</xsl:if>
 
</xsl:template>
 
 
<xsl:template match="element()" mode="copy-math" priority="5">
   
<xsl:element name="{local-name()}" namespace="http://www.w3.org/1998/Math/MathML">
     
<xsl:apply-templates select="@*|node()" mode="copy-math"/>
   
</xsl:element>
 
</xsl:template>
 
 
<xsl:template match="@*|node()" mode="copy-math">
   
<xsl:copy>
     
<xsl:apply-templates select="@*|node()" mode="copy-math"/>
   
</xsl:copy>
 
</xsl:template>
 
 
<xsl:template match="@*|node()" mode="message">
   
<xsl:copy>
     
<xsl:apply-templates select="@*|node()" mode="message"/>
   
</xsl:copy>
 
</xsl:template>
 
</xsl:stylesheet>



------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help