Transformation scenario: turn off XInclude expansion

Post here questions and problems related to oXygen frameworks/document types.
Krille
Posts: 29
Joined: Thu Nov 12, 2020 12:24 pm

Transformation scenario: turn off XInclude expansion

Post by Krille »

Hi!

Is there a way to turn of the expansion of XIncludes for a single transformation scenario automatically?

There was a discussion, where it was suggested to turn of the expansion in Options > Preferences > XML > ...
other-issues/topic10319.html
But this turns on/off XInclude expansion for the parser everywhere. This is much too complicated for our users and might lead to data corruption, if not handled with care.

I'd like offer our users a scenario, where XIncludes aren't expanded, and they needn't care about switching on/off at all.

If it isn't possible to turn off the expansion in a normal XSLT transformation scenario (because it uses oXygen's core XML parser): Would it be possible with an ANT based scenario?

Kind regards,
Christian
Radu
Posts: 8092
Joined: Fri Jul 09, 2004 5:18 pm

Re: Transformation scenario: turn off XInclude expansion

Post by Radu »

Hi Christian,

I'm afraid there is no such possibility with our XSLT based transformation scenarios.
With an ANT xslt task indeed you can control things better:
https://ant.apache.org/manual/Tasks/style.html
probably by forcing a non xi:Include aware parsing configuration:

Code: Select all

<xslt ...>
    <sysproperty key="org.apache.xerces.xni.parser.XMLParserConfiguration"
                 value="org.apache.xerces.parsers.XML11Configuration"/>
<xslt>
but this may need to be tested.
We have a pre-configured "Ant (with Saxon-HE XSLT support)" transformation scenario which should be accessible when editing ANT build files.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Krille
Posts: 29
Joined: Thu Nov 12, 2020 12:24 pm

Re: Transformation scenario: turn off XInclude expansion

Post by Krille »

Hi Radu!

That works great! If someone want's to do similar things, here's my ANT file:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<!-- ANT build script

USAGE (commandline):

ant -buildfile THISFILE \
	-Dsaxon.jar=~/.m2/repository/net/sf/saxon/Saxon-HE/10.2/Saxon-HE-10.2.jar \
	-DinputFile=SOURCE \
	-DoutputFile=DEST \
	-Dreading=lemma \
	extract-reading

-->
<project basedir="." name="ALEA">

	<!-- oxygenlib, defaults to ant lib -->
	<property name="oxygenlib" value="..."/>

	<!-- define the the saxon transformer or place it in the ant lib directory -->
	<property name="saxon.jar" value="${oxygenlib}/saxon9he.jar"/>

	<!-- Path to TEI XML file. -->
	<property name="inputFile" value=""/>

	<!-- Path where the output file will be saved. -->
	<property name="outputFile" value=""/>

	<!-- suffix of TEI documents -->
	<property name="teiSuffix">.tei.xml</property>

	<!-- author name -->
	<property name="authorname" value="${user.name}"/>

	<!-- directories -->
	<dirname property="outputDir" file="${outputFile}"/>
	<dirname property="inputDir" file="${inputFile}"/>

	<!-- modfiy basedir, if necessary: -Dbasedir=... -->
	<echo> basedir: ${basedir}</echo>

	<echo> using Saxon: ${saxon.jar}</echo>

	<!-- extract reading -->

	<property name="reading" value="lemma"/>
	<property name="recension" value=""/>

	<target name="extract-reading">
		<!-- Task for extracting a reading in order to start encoding an other recension based on it.
			This is done from ANT in order to not expand XIncludes. -->
		<xslt style="xsl/reading.xsl" in="${inputFile}" out="${outputFile}">
			<factory name="net.sf.saxon.TransformerFactoryImpl"/>
			<classpath location="${saxon.jar}"/>
			<sysproperty key="org.apache.xerces.xni.parser.XMLParserConfiguration"
				value="org.apache.xerces.parsers.XML11Configuration"/>
			<param name="reading" expression="${reading}" type="STRING"/>
			<param name="pdu" expression="${basedir}" type="STRING"/>
			<param name="note-references" expression="true" type="BOOLEAN"/>
			<param name="authorname" expression="${authorname}" type="STRING"/>
		</xslt>
		<echo>Extracted text stored in ${outputFile}</echo>
	</target>
	
	<!-- ... other tasks ... -->

</project>
Kind regards,
Christian
Radu
Posts: 8092
Joined: Fri Jul 09, 2004 5:18 pm

Re: Transformation scenario: turn off XInclude expansion

Post by Radu »

Hi Christian,

Thanks for taking the time to post the entire solution.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Krille
Posts: 29
Joined: Thu Nov 12, 2020 12:24 pm

Re: Transformation scenario: turn off XInclude expansion

Post by Krille »

Hi,

is there also a way to turn XInclude expansion on in ANT?

Kind regards,
Christian
Krille
Posts: 29
Joined: Thu Nov 12, 2020 12:24 pm

Re: Transformation scenario: turn off XInclude expansion

Post by Krille »

PS: To be more precize, I'd like XInclude processing turned on and let it be processed by the patched version of Xerces included in oXygen.
I want to use this patched version because it can process XPointer bare names (xpointer="#IDREF") and knows that @xml:id in the file to include from means IDness. (BTW, this ist great!!!) When using the unpatched version of Xerces, you have to declare IDness by DTD...
Radu
Posts: 8092
Joined: Fri Jul 09, 2004 5:18 pm

Re: Transformation scenario: turn off XInclude expansion

Post by Radu »

Hi,

If you open an ANT build file in Oxygen and use the "Configure Transformation Scenarios" toolbar button, there is a predefined transformation scenario there named "Ant (with Saxon-HE XSLT support)", if you duplicate/edit it and click the "Libraries" button, it references various libraries from Oxygen, including the "${oxygenHome}/lib/*xerces*.jar". Your transformation scenario should probably have similar library references.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Krille
Posts: 29
Joined: Thu Nov 12, 2020 12:24 pm

Re: Transformation scenario: turn off XInclude expansion

Post by Krille »

Hi Radu,
thanks for your answer! Passing all the JARs to the Ant was an important step. But it was also required to add configuration to the Ant file like described for Saxon in https://www.saxonica.com/html/documenta ... omant.html. So I added

Code: Select all

<factory name="net.sf.saxon.TransformerFactoryImpl">
	<attribute name="http://saxon.sf.net/feature/xinclude-aware" value="on"/>
</factory>
I found, that passing the Saxon jar/classpath into the XSLT task with <classpath location="${saxon.jar}"/> is not required. I think the reason is, that the paths to the JARs are passed into Ant with the -lib option. The manual page says:

Code: Select all

-lib <path>            specifies a path to search for jars and classes
Thanks and kind regards,
Christian
Radu
Posts: 8092
Joined: Fri Jul 09, 2004 5:18 pm

Re: Transformation scenario: turn off XInclude expansion

Post by Radu »

Hi Christian,

So if in the Oxygen transformation scenario you set libraries in the "Libraries" list, they are passed with "-lib" to the ANT process and indeed it's not necessary anymore to refer to them using the classpath inside the XSLT task.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply