Skip to content

Update exist-db package #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
test/result/*.xml
*.xpr
.notes.txt
47 changes: 47 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
notifications:
email: false
language: java
jdk:
- openjdk8
addons:
apt:
packages:
- libxml2-utils
services:
- docker
env:
- img=existdb/existdb:4.7.1
- img=evolvedbinary/exist-db:eXist-3.6.1-minimal
jobs:
include:
- stage: GitHub Release
before_install: skip
before_script: skip
script: skip
after_success: skip
deploy:
provider: releases
token:
secure: CmdGlijuVza6Sxp7SBb0A9xuLPX24MJoFZeZF25T/8OlWBf4LeQ7lQnQgeThfuto+iOGlleNPm/641n1Cm+9Qb95AJA9G06R/7aBw7wkVGC34fNiDODnkor/UalB//uwlGjvg8oMR0OYMhQDqJVfz+HgyxCmdy297abt9iV/t7lMsP7rctMKUvRkXgntGwSP8LrNqo9bocZV0SgE3x2nzgMId0o9mirR+yeAPvPGqaE7aJcl5hbh51JGwSVUi5xNBNW3tI0ztFdbrX1u8rGY74hEUkL93ZEicu8wwttU8cTeBOSSWF2TpRWyVRbrqhAwvklhOtnk+RQm72TaUp41ibN+t+t1FVMq2Ae5CUh+X2ZoLXuw7FDw4HmeQR4mNyVlToDlTgG4r0iZVEjIx7JFOZ1xXTb21I6fDeaJG2EvUQ7XtHUkJRHucWohwliImRQoklUOy1b/q/8iIxBrcukC9Zx2f8Sae8zKyBWW6m4Z8qAerV1W3euP/R3wcchJ/gtdUxTM5bF+r6OdmoywjEd7Wu1Yvcp0EW7IcUCTni0PQQbOsJ4ii7qvNNOqNCpibLmtzKQPLm4/GLYp2LHKTTlmEUmQWc7Ko5lXCEr7j0Adtl5dIa8+zNG4Seiwu8fSy3VwbrhL4EsV6gGYcQfkwx9F84zsl7QAUQBWbDstlzFbc0I=
file: dist/*.xar
cleanup: false
on:
tags: true

before_install:
- docker pull $img
- docker create --name exist-ci -p 8080:8080 $img
install:
- ant
- npm install -g bats
before_script:
- docker cp ./dist/*.xar exist-ci:exist/autodeploy/a1.xar
- docker start exist-ci
- sleep 30
- docker ps
script:
- curl -s "http://0.0.0.0:8080/exist/rest/db/system/repo/schematron-exist-2.0.0/test/test-suite.xq" -o test/result/test-result.xml
- bats -t test/*.bats

after_success:
- docker stop exist-ci
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,71 @@
# Schematron for eXist
[![Build Status](https://travis-ci.com/duncdrum/schematron-exist.svg?branch=master)](https://travis-ci.com/duncdrum/schematron-exist)

XQuery library module to use ISO Schematron in [eXist](http://exist-db.org/). This module uses the standard Schematron implementation from https://code.google.com/p/schematron/. This module is a port of [schematron-basex](https://github.com/Schematron/schematron-basex) to eXist.
XQuery library module to use ISO Schematron in [eXist](http://exist-db.org/). This module uses the standard Schematron implementation from [https://code.google.com/p/schematron/](https://code.google.com/p/schematron/). This module is a port of [schematron-basex](https://github.com/Schematron/schematron-basex) to eXist.

## Usage

Install the module in the way described in the eXist documentation. Go to the Dashboard and open the Package Manager. Click the add a package button, and then upload schematron-exist-1.1.xar.
Install the module in the way described in the eXist documentation. Go to the Dashboard and open the Package Manager. Click the add a package button, and then upload `schematron-exist.xar`.

After the module is installed, in your XQuery code declare the module import:

```xquery
import module namespace schematron = "http://github.com/Schematron/schematron-exist";
```

Your Schematron schema file first has to be compiled before it can be used to validate XML. The compiled Schematron can be re-used to validate multiple documents, or possibly stored in a collection for later use.

```xquery
let $sch := schematron:compile(doc('rules.sch'))
```

If your Schematron contains phases you can specify the phase to use by passing the name of the phase in the second argument.

```xquery
let $sch := schematron:compile(doc('rules.sch'), 'phase1')
```

If you need to pass additional parameters to compile the Schematron the second argument can be provided as a parameters element. The phase can be specified by including a parameter named `phase`.

```xquery
let $sch := schematron:compile(doc('rules.sch'), <parameters><param name="phase" value="phase1"/></parameters>)
```

Next, validate an XML using the compiled Schematron.

```xquery
let $svrl := schematron:validate(doc('document.xml'), $sch)
```

The validate method returns SVRL XML. This module provides several utility methods for inspecting SVRL.

To simply check whether validation has passed or failed use the is-valid method, which returns a boolean value.

```xquery
let $boolean := schematron:is-valid($svrl)
```

Schematron validation may return warnings or informational messages in addition to error messages. The has-messages method returns a boolean value to indicate if any messages are present.

```xquery
let $boolean := schematron:has-messages($svrl)
````

To get all messages that were generated as a sequence:

```xquery
let $messages := schematron:messages($svrl)
```

The message-level method returns 'error', 'warn' or 'info' (or custom values) based on the `role` attribute on Schematron `<assert>` and `<report>` elements. This method normalizes the role attribute value from the Schematron schema: if the role attribute is absent or contains 'error' or 'fatal' this method returns 'error'; if role contains 'warn' or 'warning' this method returns 'warn'; if role contains 'info' or 'information' this method returns 'info'. Any other value of the role attribute is returned unchanged.

The message-level method returns 'error', 'warn' or 'info' (or custom values) based on the `role` attribute on Schematron `<assert>` and `<report>` elements. This method normalizes the role attribute value from the Schematron schema: if the role attribute is absent or contains 'error' or 'fatal' this method returns 'error'; if role contains 'warn' or 'warning' this method returns 'warn'; if role contains 'info' or 'information' this method returns 'info'. Any other value of the role attribute is returned unchanged.
```xquery
let $level := schematron:message-level($message)
```

To get the human text description from a message:

```xquery
let $string := schematron:message-description($message)
```

To get the XPath location where a message was generated:

```xquery
let $string := schematron:message-location($message)
```

Putting this all together:

```
```xquery
import module namespace schematron = "http://github.com/Schematron/schematron-exist";

let $sch := schematron:compile(doc('rules.sch'))
Expand All @@ -80,5 +91,4 @@ This module was developed using eXist 3.0RC1, although it may work with earlier

Unit tests are located in the `test` folder. To run the unit tests open `test-suite.xq` in eXide and then click the Eval button.

The included Ant build script build.xml will create a xar file for loading into eXist.

The included Ant build script build.xml will create a `.xar` file for loading into eXist.
41 changes: 31 additions & 10 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project default="xar" name="schematron-exist">
<xmlproperty file="expath-pkg.xml"/>
<property name="project.version" value="${package(version)}"/>
<property name="project.app" value="${package(abbrev)}"/>
<property name="build.dir" value="dist"/>
<target name="xar">
<mkdir dir="${build.dir}"/>
<zip basedir="." destfile="${build.dir}/${project.app}-${project.version}.xar" excludes="dist/** .gradle/**">
</zip>
</target>
</project>
<xmlproperty file="expath-pkg.xml"/>
<property name="project.version" value="${package(version)}"/>
<property name="project.app" value="${package(abbrev)}"/>
<property name="build.dir" value="dist"/>
<target name="clean" description="cleaning old builds">
<delete failonerror="false">
<fileset dir="${build.dir}">
<include name="*.xar"/>
</fileset>
<fileset dir="test/result">
<include name="*.xml"/>
</fileset>
</delete>
<mkdir dir="test/result"/>
</target>
<target name="xar" depends='clean' description="compile all source files">
<mkdir dir="${build.dir}"/>
<zip basedir="." destfile="${build.dir}/${project.app}.xar" excludes="dist/** test/result/** *.xpr .travis.yml .notes.txt"/>
</target>
<target name="test" description="executing tests">
<mkdir dir="test/result"/>
<exec executable="curl" output="test/result/test-result.xml">
<arg value="-sL"/>
<arg value="http://0.0.0.0:8080/exist/rest/db/system/repo/${project.app}-${project.version}/test/test-suite.xq"/>
</exec>
<exec executable="bats">
<arg value="-t"/>
<arg value="test/test.bats"/>
</exec>
</target>
</project>
81 changes: 80 additions & 1 deletion content/iso-schematron/iso_abstract_expand.xsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?><?xar XSLT?>

<!--
OVERVIEW - iso_abstract_expand.xsl

This is a preprocessor for ISO Schematron, which implements abstract patterns.
It also
* extracts a particular schema using an ID, where there are multiple
schemas, such as when they are embedded in the same NVDL script
* allows parameter substitution inside @context, @test, @select, @path
* experimentally, allows parameter recognition and substitution inside
text (NOTE: to be removed, for compataibility with other implementations,
please do not use this)

This should be used after iso-dsdl-include.xsl and before the skeleton or
meta-stylesheet (e.g. iso-svrl.xsl) . It only requires XSLT 1.

Each kind of inclusion can be turned off (or on) on the command line.

-->

<!--
Open Source Initiative OSI - The MIT License:Licensing
[OSI Approved License]

This source code was previously available under the zlib/libpng license.
Attribution is polite.

The MIT License

Copyright (c) 2004-2010 Rick Jellife and Academia Sinica Computing Centre, Taiwan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<!--
VERSION INFORMATION
2013-09-19 RJ
* Allow macro expansion in @path attributes, eg. for sch:name/@path

2010-07-10 RJ
* Move to MIT license

2008-09-18 RJ
* move out param test from iso:schema template to work with XSLT 1. (Noah Fontes)

2008-07-29 RJ
* Create. Pull out as distinct XSL in its own namespace from old iso_pre_pro.xsl
* Put everything in private namespace
* Rewrite replace_substring named template so that copyright is clear

2008-07-24 RJ
* correct abstract patterns so for correct names: param/@name and
param/@value

2007-01-12 RJ
* Use ISO namespace
* Use pattern/@id not pattern/@name
* Add Oliver Becker's suggests from old Schematron-love-in list for <copy>
* Add XT -ism?
2003 RJ
* Original written for old namespace
* http://www.topologi.com/resources/iso-pre-pro.xsl
-->
<xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
Expand Down
81 changes: 0 additions & 81 deletions content/iso-schematron/iso_abstract_expand_preamble.txt

This file was deleted.

Loading