Created
April 22, 2013 18:02
-
-
Save etoyoda/5437132 to your computer and use it in GitHub Desktop.
Schematron リファレンス実装の吐く XSLT を強引に書き換えて SVRL ではなく HTML を吐く XSLT を出力する XSLT を出力するようにする XSLT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<xsl:stylesheet | |
version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:svrl="http://purl.oclc.org/dsdl/svrl" | |
> | |
<xsl:output method="xml"/> | |
<xsl:template match="/"> | |
<xsl:apply-templates select="*"/> | |
</xsl:template> | |
<xsl:template match="xsl:output"> | |
<xsl:copy> | |
<xsl:attribute name="method">html</xsl:attribute> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template | |
match="xsl:template[@match='*'][@mode='schematron-get-full-path']"> | |
<xsl:copy> | |
<xsl:attribute name="match">*</xsl:attribute> | |
<xsl:attribute name="mode">schematron-get-full-path</xsl:attribute> | |
<xsl:element name="xsl:apply-templates"> | |
<xsl:attribute name="select">parent::*</xsl:attribute> | |
<xsl:attribute name="mode">schematron-get-full-path</xsl:attribute> | |
</xsl:element> | |
<xsl:element name="xsl:text">/</xsl:element> | |
<xsl:element name="xsl:choose"> | |
<xsl:element name="xsl:when"> | |
<xsl:attribute name="test" | |
>namespace-uri()="http://www.isotc211.org/2005/gmd"</xsl:attribute> | |
<xsl:text>gmd:</xsl:text> | |
</xsl:element> | |
<xsl:element name="xsl:when"> | |
<xsl:attribute name="test" | |
>namespace-uri()="http://www.isotc211.org/2005/gco"</xsl:attribute> | |
<xsl:text>gco:</xsl:text> | |
</xsl:element> | |
<xsl:element name="xsl:when"> | |
<xsl:attribute name="test" | |
>namespace-uri()="http://www.opengis.net/gml/3.2"</xsl:attribute> | |
<xsl:text>gml:</xsl:text> | |
</xsl:element> | |
<xsl:element name="xsl:otherwise">*:</xsl:element> | |
</xsl:element> | |
<xsl:element name="xsl:value-of"> | |
<xsl:attribute name="select">local-name()</xsl:attribute> | |
</xsl:element> | |
<xsl:element name="xsl:variable"> | |
<xsl:attribute name="name">ord</xsl:attribute> | |
<xsl:attribute name="select"> | |
1 + count(preceding-sibling::*[local-name()=local-name(current())]) | |
</xsl:attribute> | |
</xsl:element> | |
<xsl:element name="xsl:if"> | |
<xsl:attribute name="test"> | |
$ord > 1 or following-sibling::*[local-name()=local-name(current())] | |
</xsl:attribute> | |
[<xsl:element name="xsl:value-of"> | |
<xsl:attribute name="select">$ord</xsl:attribute> | |
</xsl:element>] | |
</xsl:element> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="svrl:schematron-output"> | |
<html> | |
<head> | |
<title><xsl:value-of select="@title"/></title> | |
<style type="text/css"> | |
tr.MAND { background-color: #FFCCCC; } | |
tr.COND { background-color: #FFEECC; } | |
tr.REC { background-color: #FFFFCC; } | |
</style> | |
</head> | |
<body> | |
<h1>Schematron validation result</h1> | |
<p>Rule set: <xsl:value-of select="@title"/></p> | |
<p /> | |
<table border="1"> | |
<tr> | |
<th>Flag</th> | |
<th>Rule id</th> | |
<th>Location</th> | |
<th>Message</th> | |
</tr> | |
<xsl:for-each select="xsl:apply-templates"> | |
<xsl:copy-of select="."/> | |
</xsl:for-each> | |
</table> | |
</body> | |
</html> | |
</xsl:template> | |
<xsl:template match="svrl:fired-rule"> | |
<!-- | |
<tr> | |
<td>(rule)</td> | |
<td></td> | |
<td><xsl:value-of select="@context"/></td> | |
<td></td> | |
</tr> | |
--> | |
</xsl:template> | |
<xsl:template match="svrl:failed-assert|svrl:successful-report"> | |
<tr> | |
<xsl:choose> | |
<xsl:when test="starts-with(*[@name='flag'], 'M-')"> | |
<xsl:attribute name="class">MAND</xsl:attribute> | |
</xsl:when> | |
<xsl:when test="starts-with(*[@name='flag'], 'C-')"> | |
<xsl:attribute name="class">COND</xsl:attribute> | |
</xsl:when> | |
<xsl:when test="starts-with(*[@name='flag'], 'R-')"> | |
<xsl:attribute name="class">REC</xsl:attribute> | |
</xsl:when> | |
</xsl:choose> | |
<td><xsl:value-of select="*[@name='flag']"/></td> | |
<td><xsl:value-of select="*[@name='id']"/></td> | |
<td> | |
<xsl:for-each select="*[@name='location']"> | |
<xsl:copy-of select="*"/> | |
</xsl:for-each> | |
</td> | |
<td> | |
<xsl:for-each select="svrl:text"> | |
<xsl:copy-of select="*|text()"/> | |
</xsl:for-each> | |
</td> | |
</tr> | |
</xsl:template> | |
<xsl:template match="*"> | |
<xsl:copy> | |
<xsl:apply-templates select="*|@*|text()"/> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="@*"> | |
<xsl:copy-of select="." /> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment