Generate Schematron "see" attribute value

216 Views Asked by At

I would like to dynamically generate the Schematron see attribute based on the the user home's directory. I could not get this working. Do you have an idea if this is possible? It needs to work in Oxygen XML. I am not sure if this is technically not possible in Schematron, or if this is a bug in Oxygen XML.

<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
    xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
    <sch:pattern>
        <sch:rule context="/">
            <sch:let name="x" value="if (contains(base-uri(), 'myname')) 
                then 'http://www.a.com' 
                else 'http://www.b.com'"/>
            <sch:report test="'a' = 'a'">
                Hello world: "<sch:value-of select="$x"/>"
            </sch:report>
        </sch:rule>
    </sch:pattern>
</sch:schema>

My goal is to generate a user-specific link to a locally deployed style guide, but, as you can see in the screenshot, the variable x is not resolved.

Oxygen XML Results Window

3

There are 3 best solutions below

3
Radu Coravu On BEST ANSWER

Maybe you can try to read the “user.home” system property: https://www.saxonica.com/html/documentation12/functions/fn/system-property.html

1
Martin Honnen On

Using Schxslt it seems the syntax of an XSLT attribute value template in the form of e.g. see="{$x}" in Schematron then generates an SVRL report having the URI in the form of e.g.

<svrl:successful-report location="/" see="http://www.b.com" test="'a' = 'a'">
  <svrl:text>
            Hello world
        </svrl:text>
</svrl:successful-report>

I don't know whether oXygen has any integration for Schxslt as a Schematron validator and for rendering the validation result in the form of SVRL.

1
Tony Graham On

To build on the answer by @radu-coravu, you might be able to get the 'user.home' value by using a function in an external XSLT file:

  1. Use xsl:include in your Schematron file to include the XSLT. See, e.g., https://github.com/AntennaHouse/focheck/blob/43bd5d491d8b985395c94c3c53083770d8c461b6/schematron/fo-property.sch#L23
  2. Write a function in the external XSLT that returns the "user.home" system property value
  3. In your rule in your Schematron, use let to get the return value of the function as a variable value. See, e.g., https://github.com/AntennaHouse/focheck/blob/43bd5d491d8b985395c94c3c53083770d8c461b6/schematron/fo-property.sch#L31
  4. Use the Schematron variable in your assert and report just like any other variable