aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2014-09-05 20:09:08 +0200
committerAdrian Kummerlaender2014-09-05 20:09:08 +0200
commit1822c63ff75e3d67a98b9a334194da29fb0f331d (patch)
tree123223864b505e935ddb51fbcbf119a8a9ed6ff0
downloadBuildXSLT-1822c63ff75e3d67a98b9a334194da29fb0f331d.tar
BuildXSLT-1822c63ff75e3d67a98b9a334194da29fb0f331d.tar.gz
BuildXSLT-1822c63ff75e3d67a98b9a334194da29fb0f331d.tar.bz2
BuildXSLT-1822c63ff75e3d67a98b9a334194da29fb0f331d.tar.lz
BuildXSLT-1822c63ff75e3d67a98b9a334194da29fb0f331d.tar.xz
BuildXSLT-1822c63ff75e3d67a98b9a334194da29fb0f331d.tar.zst
BuildXSLT-1822c63ff75e3d67a98b9a334194da29fb0f331d.zip
Implemented basic XSLT build system
-rw-r--r--README.md33
-rw-r--r--build.xsl91
2 files changed, 124 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a8b5c29
--- /dev/null
+++ b/README.md
@@ -0,0 +1,33 @@
+# BuildXSLT
+
+... is a simple XSLT build system built on [InputXSLT](https://github.com/KnairdA/InputXSLT).
+
+## Current features:
+
+- processing tasks contained within XML _Makefiles_
+- generating single transformations
+- generating chained transformations
+- using files or embedded XML-trees as transformation input
+
+## Example:
+
+BuildXSLT can for example be used to build a [static website](https://github.com/KnairdA/TestXSLT) using the following generation chain called via `ixslt --input make.xml --transformation build.xsl`:
+
+```
+<task type="generate">
+ <input mode="embedded">
+ <datasource>
+ <meta>
+ <source>source</source>
+ <target>target</target>
+ </meta>
+ </datasource>
+ </input>
+ <transformation mode="chain">
+ <link>detail/list.xsl</link>
+ <link>detail/plan.xsl</link>
+ <link>detail/process.xsl</link>
+ <link>detail/summarize.xsl</link>
+ </transformation>
+</task>
+```
diff --git a/build.xsl b/build.xsl
new file mode 100644
index 0000000..bd57c40
--- /dev/null
+++ b/build.xsl
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet
+ version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xalan="http://xml.apache.org/xalan"
+ xmlns:InputXSLT="function.inputxslt.application"
+ exclude-result-prefixes="xalan InputXSLT"
+>
+
+<xsl:output
+ method="xml"
+ omit-xml-declaration="yes"
+ encoding="UTF-8"
+ indent="no"
+/>
+
+<xsl:template name="generate">
+ <xsl:param name="input"/>
+ <xsl:param name="transformation"/>
+
+ <xsl:copy-of select="InputXSLT:generate(
+ xalan:nodeset($input),
+ InputXSLT:read-file(string($transformation))/self::file/node()
+ )/self::generation/node()"/>
+</xsl:template>
+
+<xsl:template name="generate_chain">
+ <xsl:param name="input"/>
+ <xsl:param name="head"/>
+ <xsl:param name="tail"/>
+
+ <xsl:choose>
+ <xsl:when test="count($tail) &gt; 0">
+ <xsl:call-template name="generate">
+ <xsl:with-param name="input">
+ <xsl:call-template name="generate_chain">
+ <xsl:with-param name="input" select="$input"/>
+ <xsl:with-param name="head" select="$tail[1]"/>
+ <xsl:with-param name="tail" select="$tail[position() &gt; 1]"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ <xsl:with-param name="transformation" select="$head/text()"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="generate">
+ <xsl:with-param name="input" select="$input"/>
+ <xsl:with-param name="transformation" select="$head/text()"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="task[@type = 'generate']">
+ <xsl:variable name="input">
+ <xsl:choose>
+ <xsl:when test="input/@mode = 'embedded'">
+ <xsl:copy-of select="input/node()"/>
+ </xsl:when>
+ <xsl:when test="input/@mode = 'file'">
+ <xsl:copy-of select="InputXSLT:read-file(input/text())/self::file/node()"/>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="transformation/@mode = 'chain'">
+ <xsl:variable name="chain">
+ <xsl:for-each select="transformation/link">
+ <xsl:sort select="position()" data-type="number" order="descending"/>
+
+ <xsl:copy-of select="."/>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:call-template name="generate_chain">
+ <xsl:with-param name="input" select="$input"/>
+ <xsl:with-param name="head" select="xalan:nodeset($chain)/link[1]"/>
+ <xsl:with-param name="tail" select="xalan:nodeset($chain)/link[position() &gt; 1]"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="transformation/@mode = 'file'">
+ <xsl:call-template name="generate">
+ <xsl:with-param name="input" select="$input"/>
+ <xsl:with-param name="transformation" select="transformation/text()"/>
+ </xsl:call-template>
+ </xsl:when>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>