Sublime Forum

Creating a build system for xml xsl transformations in Windows

#1

Trying to create a build system that processes xml file with an xsl file and provides an output file.

The simplest build example at the command line is as follows:
transform example.xml -xsl:example.xsl -o:out.txt

The SaxonicaHE10.9N is the build I am trying to incorporate since it is license free.

I am open to any ideas that would help make this happen.

I think my biggest stumbling block is passing multiple parameters to the build system and opening the output file after the transformation.

Are there any packages I can leverage?

***example.xml***
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="example.xsl"?>
<Article>
  <Title>My Article</Title>
  <Authors>
    <Author>Mr. Foo</Author>
    <Author>Mr. Bar</Author>
  </Authors>
  <Body>This is my article text.</Body>
</Article>

***example.xsl***
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:template match="/">
    Article - <xsl:value-of select="/Article/Title"/>
    Authors: <xsl:apply-templates select="/Article/Authors/Author"/>
  </xsl:template>
  <xsl:template match="Author">
    - <xsl:value-of select="." />
  </xsl:template>
</xsl:stylesheet>

***out.txt***
    Article - My Article
    Authors: 
    - Mr. Foo
    - Mr. Bar
0 Likes

#2

ST build systems are not designed to be passed arguments to. However various various variants can be configured, each using a distinct set of arguments (e.g.: stylesheets).

The following build system transforms an open xml ${file} to a text file with same name in the same folder, using a stylsheet matching input file’s name, by default. The output file is opened via subl after creation.

Multiple "variants" could be used to apply different stylesheets.

{
	"selector": "text.xml",

	"shell_cmd": "transform \"${file}\" -xsl:${file_base_name}.xsl -o \"${file_base_name}.txt\" && subl \"${file_base_name}.txt\"",
	"working_dir": "${file_path}",

	"variants": [
		{
			"name": "Extract Articles",
			"shell_cmd": "transform \"${file}\" -xsl:articles.xsl -o \"${file_base_name}.txt\" && subl \"${file_base_name}.txt\"",
		}
	],
}

More complicated build system scripts may be implemented as shell script, which can be invoked via build system then.

0 Likes

#3

Thank you so much for this. I can see how I can make this work.

I also see a possible solution if I could pre-process the files into a working directory, change names to be alike and then invoke the build system with the hard-coded working directory.

I guess what I am getting at is to increase the flexibility of which files to choose to apply before the invocation.

Again, thank you so much for your thoughts. I am completely new to ST.

0 Likes