[xsl] Moving stylesheet from Java Saxon to .NET Saxon

Subject: [xsl] Moving stylesheet from Java Saxon to .NET Saxon
From: "Mark Wilson pubs@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 6 Apr 2017 16:51:34 -0000
I have always used the Java version of Saxon but have been asked to supply a .Net version of a stylesheet and Windows batch file. I have never used .NET. Can anyone tell me what has to change to do this? Obviously, the call to Java must change, but how, and what else?
The batch file and stylesheet are below.
Mark


REM Mark Wilson 25 March 2017
ECHO OFF
REM
REM Steve, if needed, remove files from earlier 'content.subject' directory
REM Simply remove 'REM' from the next line
REM rmdir content.subject /s
java -jar saxon97\saxon9he.jar -it:main -xsl:xslt/content.subject.xsl
md processed
cd xml
move *.xml ../processed
cd ../
--------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:xs="http://www.w3.org/2001/XMLSchema"; exclude-result-prefixes="xs" version="2.0">


<!--
    Mark Wilson 25 March 2017
editor@xxxxxxxxxxxx

Select and concat content.subject elements matched with priref element.
Construct output csv file name from input xml file name.
Requires Saxon 9.7 HE (Java version)


Programming assumptions:
Input XML is well formed,
<priref> element appears once in <record> element and always before <content.subject> element
No other elements appear between <content.subject> elements
-->


    <!-- Discard lines resulting from unwanted records -->
    <xsl:strip-space elements="*"/>

<!-- There is no command line xml document; inputs are the xml documents in the xml child directory
Requires Saxon 'it:main' command line switch in batch file -->
<xsl:template name="main">
<xsl:for-each select="collection('../xml/?select=*.xml')">
<xsl:apply-templates/>
</xsl:for-each>
</xsl:template>


<!-- Construct each output document's name from the xml file's name
destination child directory + xml file name + csv extent -->
<xsl:template match="adlibXML">
<xsl:variable name="file-name-out" select="concat('content.subject/', substring-before((tokenize(document-uri(/),'/'))[last()], '.'), '.csv')"/>
<xsl:result-document href="{$file-name-out}" encoding="UTF-8" method="text">
<xsl:apply-templates/>
</xsl:result-document>
</xsl:template>


     <!-- Create headings -->
    <xsl:template match="recordList">
<xsl:text>priref&#9;content.subject&#xa;</xsl:text>
        <xsl:apply-templates/>
    </xsl:template>

    <!-- Process only records with content.subject elements -->
    <xsl:template match="record">
        <xsl:if test="content.subject">
            <xsl:apply-templates/>
        </xsl:if>
    </xsl:template>

    <!-- Process priref element -->
    <xsl:template match="priref">
        <xsl:value-of select="."/>
        <!-- Tab for end of field -->
        <xsl:text>&#9;</xsl:text>
    </xsl:template>

<!-- Process content.subject element -->
<xsl:template match="content.subject">
<xsl:value-of select="."/>
<!-- Either add siblings with a comma or end row with a newline -->
<xsl:choose>
<xsl:when test="following-sibling::content.subject">
<xsl:text>, </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>&#xa;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


    <!-- Unwanted element sink -->
    <xsl:template match="content.subject.lref"/>
    <xsl:template match="content.description"/>
    <xsl:template match="creator"/>
    <xsl:template match="creator.lref"/>
    <xsl:template match="creator.role.lref"/>
    <xsl:template match="description_level"/>
    <xsl:template match="diagnostic"/>
    <xsl:template match="digital_reference"/>
    <xsl:template match="digital_reference.description"/>
    <xsl:template match="dimension.type"/>
    <xsl:template match="dimension.type.lref"/>
    <xsl:template match="dimension.notes"/>
    <xsl:template match="dimension.part"/>
    <xsl:template match="dimension.unit"/>
    <xsl:template match="dimension.unit.lref"/>
    <xsl:template match="dimension.value"/>
    <xsl:template match="dimension.free"/>
    <xsl:template match="object_number"/>
    <xsl:template match="parts_reference"/>
    <xsl:template match="parts_reference.lref"/>
    <xsl:template match="part_of_reference"/>
    <xsl:template match="part_of_reference.lref"/>
    <xsl:template match="part_of.description_level"/>
    <xsl:template match="part_of.notes"/>
    <xsl:template match="part_of.title"/>
    <xsl:template match="production.date.start"/>
    <xsl:template match="production.date.end"/>
    <xsl:template match="related_object.reference"/>
    <xsl:template match="related_object.reference.lref"/>
    <xsl:template match="reproduction.reference"/>
    <xsl:template match="reproduction.reference.lref"/>
    <xsl:template match="title"/>

</xsl:stylesheet>

Current Thread