diff options
Implemented basic page compilation facilities
* templates in 'template/compiler' are automatically generated
** required datasources are extracted and merged automatically
** 'pages.xsl' is currently a dummy compiler
* moved context helper templates into context stylesheet
* added compiler directory to meta DOM
* modified generator and transformer helper templates to enable usage of DOM as input
-rw-r--r-- | generate.xsl | 80 | ||||
-rw-r--r-- | meta.xml | 1 | ||||
-rw-r--r-- | template/compiler/pages.xsl | 25 | ||||
-rw-r--r-- | template/datasource/pages.xsl | 8 | ||||
-rw-r--r-- | utility/context.xsl | 49 | ||||
-rw-r--r-- | utility/datasource.xsl | 2 | ||||
-rw-r--r-- | utility/generator.xsl | 4 | ||||
-rw-r--r-- | utility/transformer.xsl | 2 |
8 files changed, 131 insertions, 40 deletions
diff --git a/generate.xsl b/generate.xsl index 65a49f3..e0e8121 100644 --- a/generate.xsl +++ b/generate.xsl @@ -14,55 +14,77 @@ indent="yes" /> -<xsl:include href="utility/transformer.xsl"/> -<xsl:include href="utility/generator.xsl"/> +<xsl:include href="utility/context.xsl"/> +<xsl:include href="utility/reader.xsl"/> -<xsl:variable name="context" select="/"/> - -<xsl:template name="transform_in_context"> - <xsl:param name="input"/> +<xsl:template name="generate_datasource"> + <xsl:param name="source"/> <xsl:param name="transformation"/> - <xsl:call-template name="transformer"> - <xsl:with-param name="input"> - <data> - <xsl:copy-of select="$context"/> - <xsl:copy-of select="$input"/> - </data> - </xsl:with-param> - <xsl:with-param name="transformation" select="$transformation"/> + <xsl:call-template name="generate_in_context"> + <xsl:with-param name="input" select="$source"/> + <xsl:with-param name="transformation" select="string($transformation/full)"/> + <xsl:with-param name="target" select="concat($context/target/datasource, '/', $transformation/name, '.xml')"/> </xsl:call-template> </xsl:template> -<xsl:template name="generate_in_context"> - <xsl:param name="input"/> +<xsl:template name="read_datasource"> + <xsl:param name="name"/> + + <xsl:variable name="datasource"> + <xsl:call-template name="reader"> + <xsl:with-param name="path" select="concat($context/target/datasource, '/', $name)"/> + </xsl:call-template> + </xsl:variable> + + <datasource name="{$name}"> + <xsl:copy-of select="xalan:nodeset($datasource)/datasource/*"/> + </datasource> +</xsl:template> + +<xsl:template name="compile"> <xsl:param name="transformation"/> - <xsl:param name="target"/> - <xsl:call-template name="generator"> + <xsl:variable name="stylesheet"> + <xsl:call-template name="reader"> + <xsl:with-param name="path" select="$transformation/full"/> + </xsl:call-template> + </xsl:variable> + + <xsl:variable name="datasources" select=" + xalan:nodeset($stylesheet)/*[name() = 'xsl:stylesheet'] + /*[name() = 'xsl:variable' and @name = 'datasources'] + "/> + + <xsl:call-template name="transform_in_context"> <xsl:with-param name="input"> - <data> - <xsl:copy-of select="$context"/> - <xsl:copy-of select="$input"/> - </data> + <xsl:for-each select="$datasources/file"> + <xsl:call-template name="read_datasource"> + <xsl:with-param name="name" select="@name"/> + </xsl:call-template> + </xsl:for-each> </xsl:with-param> - <xsl:with-param name="transformation" select="$transformation"/> - <xsl:with-param name="target" select="$target"/> + <xsl:with-param name="transformation" select="$stylesheet"/> </xsl:call-template> </xsl:template> <xsl:template match="meta"> <xsl:variable name="source"> <xsl:call-template name="transform_in_context"> - <xsl:with-param name="transformation">[source.xsl]</xsl:with-param> + <xsl:with-param name="transformation" select="string('[source.xsl]')"/> </xsl:call-template> </xsl:variable> <xsl:for-each select="InputXSLT:read-directory(./source/datasource)/entry[./extension = '.xsl']"> - <xsl:call-template name="generate_in_context"> - <xsl:with-param name="input" select="$source"/> - <xsl:with-param name="transformation" select="./full"/> - <xsl:with-param name="target" select="concat($context/meta/target/datasource, '/', ./name, '.xml')"/> + <xsl:call-template name="generate_datasource"> + <xsl:with-param name="source" select="$source"/> + <xsl:with-param name="transformation" select="."/> + </xsl:call-template> + </xsl:for-each> + + <xsl:for-each select="InputXSLT:read-directory(./source/compiler)/entry[./extension = '.xsl']"> + <xsl:call-template name="compile"> + <xsl:with-param name="transformation" select="."/> </xsl:call-template> </xsl:for-each> </xsl:template> @@ -9,6 +9,7 @@ <source> <content>/home/common/projects/dev/static_site_generator/source</content> <datasource>/home/common/projects/dev/static_site_generator/template/datasource</datasource> + <compiler>/home/common/projects/dev/static_site_generator/template/compiler</compiler> <output>/home/common/projects/dev/static_site_generator/template/output</output> </source> </meta> diff --git a/template/compiler/pages.xsl b/template/compiler/pages.xsl new file mode 100644 index 0000000..f4ada83 --- /dev/null +++ b/template/compiler/pages.xsl @@ -0,0 +1,25 @@ +<?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="no" + encoding="UTF-8" + indent="yes" +/> + +<xsl:variable name="datasources"> + <file name="pages.xml"/> +</xsl:variable> + +<xsl:template match="datasource[@name = 'pages.xml']/entry"> + <compile>Compile page: <xsl:value-of select="@handle"/></compile> +</xsl:template> + +</xsl:stylesheet> diff --git a/template/datasource/pages.xsl b/template/datasource/pages.xsl index c77513a..5c036c9 100644 --- a/template/datasource/pages.xsl +++ b/template/datasource/pages.xsl @@ -10,13 +10,7 @@ <xsl:include href="[utility/datasource.xsl]"/> <xsl:include href="[utility/formatter.xsl]"/> -<xsl:template match="source/pages"> - <pages> - <xsl:apply-templates select="./*"/> - </pages> -</xsl:template> - -<xsl:template match="file[./extension = '.md']"> +<xsl:template match="source/pages/file[./extension = '.md']"> <entry handle="{./name}"> <xsl:choose> <xsl:when test="./extension = '.md'"> diff --git a/utility/context.xsl b/utility/context.xsl new file mode 100644 index 0000000..87447bf --- /dev/null +++ b/utility/context.xsl @@ -0,0 +1,49 @@ +<?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:include href="generator.xsl"/> +<xsl:include href="transformer.xsl"/> + +<xsl:variable name="context" select="meta"/> + +<xsl:template name="transform_in_context"> + <xsl:param name="input"/> + <xsl:param name="transformation"/> + + <xsl:call-template name="transformer"> + <xsl:with-param name="input"> + <data> + <xsl:copy-of select="$context"/> + <xsl:copy-of select="$input"/> + </data> + </xsl:with-param> + <xsl:with-param name="transformation" select="$transformation"/> + </xsl:call-template> +</xsl:template> + +<xsl:template name="generate_in_context"> + <xsl:param name="input"/> + <xsl:param name="transformation"/> + <xsl:param name="target"/> + + <xsl:call-template name="generator"> + <xsl:with-param name="input"> + <data> + <xsl:copy-of select="$context"/> + <xsl:copy-of select="$input"/> + </data> + </xsl:with-param> + <xsl:with-param name="transformation" select="$transformation"/> + <xsl:with-param name="target" select="$target"/> + </xsl:call-template> +</xsl:template> + +<xsl:template match="text()|@*"/> + +</xsl:stylesheet> diff --git a/utility/datasource.xsl b/utility/datasource.xsl index 02b37d1..8ce224c 100644 --- a/utility/datasource.xsl +++ b/utility/datasource.xsl @@ -14,7 +14,7 @@ indent="yes" /> -<xsl:template match="data"> +<xsl:template match="/"> <datasource> <xsl:apply-templates /> </datasource> diff --git a/utility/generator.xsl b/utility/generator.xsl index ca6f0c3..eb65996 100644 --- a/utility/generator.xsl +++ b/utility/generator.xsl @@ -14,8 +14,8 @@ <xsl:copy-of select="InputXSLT:generate( $input, - string($transformation), - string($target) + $transformation, + $target )/self::generation"/> </xsl:template> diff --git a/utility/transformer.xsl b/utility/transformer.xsl index 6c85a4e..0812f33 100644 --- a/utility/transformer.xsl +++ b/utility/transformer.xsl @@ -13,7 +13,7 @@ <xsl:copy-of select="InputXSLT:transform( $input, - string($transformation) + $transformation )/self::transformation/*"/> </xsl:template> |