Customer function in schematron

Here should go questions about transforming XML with XSLT and FOP.
cjhukill
Posts: 11

Customer function in schematron

Mon Mar 21, 2016 4:26 pm

I am attempting to add a custom function to my schematron rule stylesheet to aid in looking up values in code tables. I continue to receive an error message: "unrecognized element xsl:function from namespace http://www.w3.org/1999/Transform''

At the top of the file, I have the following declarations:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron"
xmlns:sch="http://purl.oclc.org/dsdl/schematron"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:local-fn="functions:1.0"
xmlns:regexp="http://exslt.org/regular-expressions"
queryBinding="xslt2">

<sch:ns uri="functions:1.0" prefix="local-fn" />


and the function declaration as:

Code: Select all

<!-- *********************************** Functions *********************** -->
<!-- special variables for lookup table -->
<xsl:key name="Code-Lookup" match="CodeTable" use="Code"/>
<xsl:variable name="codeTables" select="document('LookupCodes.xml')/CodeTable"/>
<!-- function to return an expression to be evaluated in the rule containing the codes from the given code table -->
<xsl:function name="local-fn:BuildLookupExpression" as="xs:string">
<xsl:param name="TableName" as="xs:string"/>
<xsl:text>(</xsl:text>
<xsl:for-each select="key('Code-Lookup', $TableName)/Code">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<xsl:text>)|(</xsl:text>
</xsl:if>
<xsl:if test="position() = last()">
<xsl:text>)</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:function>



in the body, I use the rule:

Code: Select all

<sch:pattern id="SEXValue">
<sch:title>Person Sex</sch:title>
<sch:p class="description">
This field is used to report the gender of the subject.
See SEX Table: [F, G, M, N, X, Y, Z]
</sch:p>

<let name="SEXExpression" value="local-fn:BuildLookupExpression('SEX')"/>
<sch:rule context="nc:PersonSexCode">
<let name="SEXString" value="string(.)"/>
<sch:assert test="matches($SEXString, $SEXExpression)">
<sch:value-of select="name(.)" /> must be in the set of: [F, G, M, N, X, Y, Z]
</sch:assert>
</sch:rule>
</sch:pattern>


What am I missing?
radu_pisoi
Posts: 327
Location: Craiova

Re: Customer function in schematron

Tue Mar 22, 2016 11:47 am

Hi,

Thank you for contacting us.

You should activate the option 'Allow foreign elements (allow-foreign)' from the 'XML / XML Parser / Schematron' option page. This option is used to pass non-Schematron elements to the generated stylesheet.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
cjhukill
Posts: 11

Re: Customer function in schematron

Tue Mar 22, 2016 9:26 pm

Thank for you quick reply. I set that in my environment and all is working as planned. THANK YOU!!

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 2 guests