phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
110 stars 36 forks source link

Revert to Saxon version 9*? 【question】 #129

Closed zzllkk2003 closed 2 years ago

zzllkk2003 commented 2 years ago

hi phax,

The Saxon-HE version does not support the use of custom extension functions in xslt. If used after 11. So how should we use the function in xslt?

please see at https://www.saxonica.com/documentation9.5/extensions/functions/saxon-extension-functions.html

this is the same problem as https://github.com/phax/ph-schematron/issues/112

phax commented 2 years ago

Well, generally speaking, a downgrade of the main Saxon version is not an option for me. Especially as the version 9 is no longer actively developed.

But I guess (I do not know) there is an easy possibility to "include" all the functions that you need inside your Schematron. Look e.g. at https://www.oxygenxml.com/forum/topic13057.html on how that can be achieved. Just make sure schematronResource.setAllowForeignElements (true); is called before evaluating it.

zzllkk2003 commented 2 years ago

hi phax

My current situation is that I need to write a java program to process xml content. There are two steps here:

A. I expect to be able to use ph-schematron to check the correctness of the xml content data. If it is wrong, it will throw and get the error message content text, B If step A is correct, use saxon to convert xml to json content. (The external extension function of saxon will be used here)

If step A uses saxon 11, but step B uses saxon 9(Actually we need to use extension functions, we chose saxon-b 9.1.0.8,please see at http://saxon.sourceforge.net/), then our program won't work properly. In this case, how do we use ph-schematron?

Here is a minimal example xslt file for our step 2. We want to try to introduce our own extended functions in our xslt file, such as com.example.util.MetaDataXsltUtil.turnStandardInfo2Biz(String a ,String b)

<?xml version="1.0" encoding="utf-8"?>
<!-- use xslt 2.0  + saxon extension function -->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:cf="java:com.examplet.utils.MetaDataXsltUtil"
                exclude-result-prefixes="cf"
                xpath-default-namespace="urn:hl7-org:v3">
<xsl:output method="text" encoding="utf-8"  />
<xsl:template match="/">
    {
    "processingCode":"<xsl:value-of select="/PRPA_IN201305UV02/processingCode/@code"/>",
    "genderCode":"<xsl:value-of select="cf:turnStandardInfo2Biz(/PRPA_IN201305UV02/controlActProcess/queryByParameter/parameterList/livingSubjectAdministrativeGender/value/@code,'genderCode',/PRPA_IN201305UV02/controlActProcess/queryByParameter/parameterList/livingSubjectAdministrativeGender/value/@codeSystem)"/>",
    "patientName":"<xsl:value-of select="/PRPA_IN201305UV02/controlActProcess/queryByParameter/parameterList/livingSubjectName/value/item/part/@value"/>"
    }
</xsl:template>
</xsl:stylesheet>

For example, using saxon-HE 11, how to modify the above example so that I can run normally?

zzllkk2003 commented 2 years ago

hi phax In this example, I can't get it to work with the saxon-he 11 version. If we can run this case, we can use ph-schematron.

https://stackoverflow.com/questions/33392114/saxon-he-integrated-extension-functions-how-and-where?newreg=04568f9374d34cb991e39b00abc2adf6
phax commented 2 years ago

@zzllkk2003 Please see the latest commit for class Issue129Test - it shows how to use Saxon Java extension functions with Saxon 11

phax commented 2 years ago

And here is an example, how to handle an extension function with a parameter

zzllkk2003 commented 2 years ago

thx, phax.
I have seen 129 for this example. It works locally.

I will try it myself without sch, directly use xslt to convert xml to json.

By the way, if I want to implement the above two steps: A. Check the xml content, B Convert the xml content to json.

Do we have to write two files, .sch file and *.xsl? Is it impossible to accomplish these two tasks with only .sch?

phax commented 2 years ago

Schematron is only for checking. So you need to do it an extra step. The result of Schematron is always SVRL.

So you need 2 scripts.

phax commented 2 years ago

@zzllkk2003 I assume it works? Can this issue be closed?

phax commented 2 years ago

Closing this issue for now. I guess everything works as expected. Feel free to reopen if you have continuous issues.