SCH: initialize a variable during built to XSLT

Here should go questions about transforming XML with XSLT and FOP.
DanOvergaard
Posts: 22
Joined: Thu Jan 07, 2021 10:44 am

SCH: initialize a variable during built to XSLT

Post by DanOvergaard »

Hi,

We have a process where our XSLT's are built by a Schema Schematron process and I need to initialize a variable during built. Is there away to "tell" the process that it should execute an XSL Texpression, not just implement it in the final XLST?

I have tried different approvers to get the following XLST expression executed through the SCH-file, but no luck so fare

Code: Select all

 <xsl:variable name="PartyLegalID"><xsl:value-of select="document('PartyLegalID.xml')//default:Code/default:Id/normalize-space()" separator=","/></xsl:variable>
Rgds,
Dan
tavy
Posts: 365
Joined: Thu Jul 01, 2004 12:29 pm

Re: SCH: initialize a variable during built to XSLT

Post by tavy »

Hi Dan,

I don't know if I understand exactly what you intend tot do. Maybe you can send us a sample Schematron file and explain what you want to obtain.
The XSLT content from the Schematron will be automatically executed. For your example, if you use <sch:value-of select="$PartyLegalID"/> in the Schematron assert, you will obtain the value from the "PartyLegalID.xml" document.

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
DanOvergaard
Posts: 22
Joined: Thu Jan 07, 2021 10:44 am

Re: SCH: initialize a variable during built to XSLT

Post by DanOvergaard »

Hi Octavian,

I look for a way to initialize the variable “PartyLegalID” during the schema schematron build process, with the values from the PartyLegalID.xml (See below). So I try to implement something like
  • In the sch-file I have an empty variable called “PartyLegalID”
  • During build, the variable should be initialized with the values from the “PartyLegalID.xml” and then used to create the variable in the final xsl-file - where it should look like:
    • <xsl:variable name="PartyLegalID " select="',DK:CVR,ZZZ,'"/>

Xml-file that holds the values

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<CodeList xmlns="erst.dk:2023:structure:CodeList-1">
    <Title>PartyLegalID</Title>
    <Code>
        <Id>DK:CVR</Id>
        <Name>Juridisk identifikation af virksomheden</Name>
    </Code>
    <Code>
        <Id>ZZZ</Id>
        <Name>Angivelse af at virksomheden er udenlandsk</Name>
    </Code>
</CodeList>


Note
Original the variables were initialized in the sch-file (See below), but I have been requested to move the values out of the sch-file an into a separate XML-file (mainly due to maintenance/documentation reasons) and the “PartyLegalID” variables are only one are many (some huge) that I need to be “moved”.


Original variable initialization

Code: Select all

<sch:let name="PartyLegalID_old"          value="',DK:CVR,ZZZ,'"/>

I hope that clarify what I am trying to achieve

Rgds,
Dan
Martin Honnen
Posts: 97
Joined: Tue Aug 19, 2014 12:04 pm

Re: SCH: initialize a variable during built to XSLT

Post by Martin Honnen »

It looks to me as if you should be able to use the other document in a Schematron variable e.g.

Code: Select all

<sch:let name="PartyLegalId"
        value="doc('PartyLegalId.xml')//*:defaultId/normalize-space() => string-join(',')"/>
(queryBinding="xslt3") or

Code: Select all

<sch:let name="PartyLegalId"
        value="string-join(doc('PartyLegalId.xml')//*:defaultId/normalize-space(), ',')"/>
for XSLT 2.

There might be better ways with namespace and the original path you had but the main idea is to just use sch:let value with an XPath expression that selects/computes the value you want.
DanOvergaard
Posts: 22
Joined: Thu Jan 07, 2021 10:44 am

Re: SCH: initialize a variable during built to XSLT

Post by DanOvergaard »

Hi Martin,

Thanks for your reply

Unfortunately, it didn't import the values from the external XML file during the process from SCH to XSL.

I am trying to get the SCH file to import the values during build and insert the result in the final XSL file, so the variable "PartyLegalID" = "DK:CVR,ZZZ" (I can't just put the values in the definition of the variable as the values are maintained in another system)

I might need to open the build process, but it has run for years and there is no documentation or source code :shock:

If you have any good suggestions, please let me know

Rgds,
Dan
Post Reply