diff options
-rw-r--r-- | generate.xsl | 177 | ||||
-rw-r--r-- | meta.xml | 15 | ||||
-rw-r--r-- | source/00_content/meta.xml | 5 | ||||
-rw-r--r-- | source/00_content/pages/about.md (renamed from source/pages/about.md) | 0 | ||||
-rw-r--r-- | source/00_content/pages/contact.md (renamed from source/pages/contact.md) | 0 | ||||
-rw-r--r-- | source/01_files/source.xsl | 51 | ||||
-rw-r--r-- | source/02_data/pages.xsl (renamed from template/datasource/pages.xsl) | 14 | ||||
-rw-r--r-- | source/03_result/page.xsl | 35 | ||||
-rw-r--r-- | template/compiler/pages.xsl | 33 | ||||
-rw-r--r-- | template/output/page.xsl | 23 | ||||
-rw-r--r-- | utility/context.xsl | 47 | ||||
-rw-r--r-- | utility/generator.xsl | 22 | ||||
-rw-r--r-- | utility/master.xsl (renamed from template/output/master.xsl) | 28 | ||||
-rw-r--r-- | utility/reader.xsl | 16 | ||||
-rw-r--r-- | utility/transformer.xsl | 20 | ||||
-rw-r--r-- | utility/writer.xsl | 20 |
16 files changed, 233 insertions, 273 deletions
diff --git a/generate.xsl b/generate.xsl index 04a9c2f..405f940 100644 --- a/generate.xsl +++ b/generate.xsl @@ -2,9 +2,10 @@ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:dyn="http://exslt.org/dynamic" xmlns:xalan="http://xml.apache.org/xalan" xmlns:InputXSLT="function.inputxslt.application" - exclude-result-prefixes="xalan InputXSLT" + exclude-result-prefixes="dyn xalan InputXSLT" > <xsl:output @@ -14,80 +15,128 @@ indent="yes" /> -<xsl:include href="utility/context.xsl"/> -<xsl:include href="utility/reader.xsl"/> - -<xsl:variable name="context" select="meta"/> - -<xsl:template name="generate_datasource"> - <xsl:param name="source"/> +<xsl:template name="generator"> + <xsl:param name="input"/> <xsl:param name="transformation"/> + <xsl:param name="target"/> - <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="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:copy-of select="InputXSLT:generate( + $input, + $transformation, + $target + )/self::generation"/> </xsl:template> -<xsl:template name="compile"> +<xsl:template name="compiler"> + <xsl:param name="input"/> <xsl:param name="transformation"/> - - <xsl:variable name="stylesheet"> - <xsl:call-template name="reader"> - <xsl:with-param name="path" select="$transformation/full"/> - </xsl:call-template> + <xsl:param name="target_prefix"/> + <xsl:param name="target"/> + + <xsl:variable name="resolved_target"> + <xsl:choose> + <xsl:when test="$target/@mode = 'plain'"> + <xsl:value-of select="$target/@value"/> + </xsl:when> + <xsl:when test="$target/@mode = 'xpath'"> + <xsl:value-of select="dyn:evaluate($target/@value)"/> + </xsl:when> + <xsl:otherwise> + + </xsl:otherwise> + </xsl:choose> </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"> - <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="$stylesheet"/> + <xsl:call-template name="generator"> + <xsl:with-param name="input" select="$input"/> + <xsl:with-param name="transformation" select="$transformation"/> + <xsl:with-param name="target" select="concat($target_prefix, '/', $resolved_target)"/> </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" 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_datasource"> - <xsl:with-param name="source" select="$source"/> - <xsl:with-param name="transformation" select="."/> - </xsl:call-template> - </xsl:for-each> +<xsl:template name="datasource"> + <xsl:param name="main"/> + <xsl:param name="support"/> + + <datasource> + <xsl:copy-of select="$main"/> + <xsl:for-each select="$support"> + <xsl:element name="{./@target}"> + <xsl:choose> + <xsl:when test="./@mode = 'full'"> + <xsl:copy-of select="InputXSLT:read-file(./@source)/self::file/*/*"/> + </xsl:when> + <xsl:otherwise> + </xsl:otherwise> + </xsl:choose> + </xsl:element> + </xsl:for-each> + </datasource> +</xsl:template> - <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:template match="/"> + <xsl:for-each select="InputXSLT:read-directory('source/')/entry[@type = 'directory']"> + <xsl:variable name="level" select="."/> + + <xsl:for-each select="InputXSLT:read-directory(./full)/entry[./extension = '.xsl']"> + <xsl:variable name="transformation" select="."/> + <xsl:variable name="stylesheet" select="InputXSLT:read-file($transformation/full)/self::file/*"/> + <xsl:variable name="meta" select="$stylesheet/self::*[name() = 'xsl:stylesheet']/*[name() = 'xsl:variable' and @name = 'meta']"/> + <xsl:variable name="main" select="$meta/datasource[@type = 'main']"/> + + <xsl:choose> + <xsl:when test="$main/@mode = 'full'"> + <xsl:call-template name="compiler"> + <xsl:with-param name="input"> + <xsl:call-template name="datasource"> + <xsl:with-param name="main"> + <xsl:element name="{$main/@target}"> + <xsl:copy-of select="InputXSLT:read-file($main/@source)/self::file/*/*"/> + </xsl:element> + </xsl:with-param> + <xsl:with-param name="support" select="$meta/datasource[@type = 'support']"/> + </xsl:call-template> + </xsl:with-param> + <xsl:with-param name="transformation" select="$stylesheet"/> + <xsl:with-param name="target_prefix" select="concat('target/', $level/name)"/> + <xsl:with-param name="target" select="$meta/target"/> + </xsl:call-template> + </xsl:when> + <xsl:when test="$main/@mode = 'iterate'"> + <xsl:variable name="datasource" select="InputXSLT:read-file($main/@source)/self::file/*"/> + + <xsl:for-each select="$datasource/entry"> + <xsl:call-template name="compiler"> + <xsl:with-param name="input"> + <xsl:call-template name="datasource"> + <xsl:with-param name="main"> + <xsl:element name="{$main/@target}"> + <xsl:copy-of select="."/> + </xsl:element> + </xsl:with-param> + <xsl:with-param name="support" select="$meta/datasource[@type = 'support']"/> + </xsl:call-template> + </xsl:with-param> + <xsl:with-param name="transformation" select="$stylesheet"/> + <xsl:with-param name="target_prefix" select="concat('target/', $level/name)"/> + <xsl:with-param name="target" select="$meta/target"/> + </xsl:call-template> + </xsl:for-each> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="compiler"> + <xsl:with-param name="input"> + <xsl:call-template name="datasource"> + <xsl:with-param name="support" select="$meta/datasource[@type = 'support']"/> + </xsl:call-template> + </xsl:with-param> + <xsl:with-param name="transformation" select="$stylesheet"/> + <xsl:with-param name="target_prefix" select="concat('target/', $level/name)"/> + <xsl:with-param name="target" select="$meta/target"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> </xsl:for-each> </xsl:template> diff --git a/meta.xml b/meta.xml deleted file mode 100644 index 3dca27c..0000000 --- a/meta.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<meta> - <title>/home/adrian</title> - <target> - <datasource>/home/common/projects/dev/static_site_generator/datasource</datasource> - <output>/home/common/projects/dev/static_site_generator/result</output> - <public>/home/common/projects/dev/static_site_generator/result</public> - </target> - <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/source/00_content/meta.xml b/source/00_content/meta.xml new file mode 100644 index 0000000..8c1af22 --- /dev/null +++ b/source/00_content/meta.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<meta> + <title>/home/adrian</title> + <url>/home/common/projects/dev/static_site_generator/target/03_result</url> +</meta> diff --git a/source/pages/about.md b/source/00_content/pages/about.md index 827b612..827b612 100644 --- a/source/pages/about.md +++ b/source/00_content/pages/about.md diff --git a/source/pages/contact.md b/source/00_content/pages/contact.md index a9d8be1..a9d8be1 100644 --- a/source/pages/contact.md +++ b/source/00_content/pages/contact.md diff --git a/source/01_files/source.xsl b/source/01_files/source.xsl new file mode 100644 index 0000000..d13e3bd --- /dev/null +++ b/source/01_files/source.xsl @@ -0,0 +1,51 @@ +<?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="meta"> + <datasource type="main"/> + <target mode="plain" value="source.xml"/> +</xsl:variable> + +<xsl:template name="list_source"> + <xsl:param name="base"/> + + <xsl:for-each select="InputXSLT:read-directory($base)/entry"> + <xsl:choose> + <xsl:when test="@type = 'directory'"> + <xsl:element name="{./name}"> + <xsl:call-template name="list_source"> + <xsl:with-param name="base" select="./full"/> + </xsl:call-template> + </xsl:element> + </xsl:when> + <xsl:otherwise> + <file> + <xsl:copy-of select="./*"/> + </file> + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> +</xsl:template> + +<xsl:template match="/"> + <datasource> + <xsl:call-template name="list_source"> + <xsl:with-param name="base">[source/00_content]</xsl:with-param> + </xsl:call-template> + </datasource> +</xsl:template> + +</xsl:stylesheet> diff --git a/template/datasource/pages.xsl b/source/02_data/pages.xsl index 5c036c9..4f3002f 100644 --- a/template/datasource/pages.xsl +++ b/source/02_data/pages.xsl @@ -7,10 +7,22 @@ exclude-result-prefixes="xalan InputXSLT" > +<xsl:output + method="xml" + omit-xml-declaration="no" + encoding="UTF-8" + indent="yes" +/> + <xsl:include href="[utility/datasource.xsl]"/> <xsl:include href="[utility/formatter.xsl]"/> -<xsl:template match="source/pages/file[./extension = '.md']"> +<xsl:variable name="meta"> + <datasource type="main" mode="full" source="target/01_files/source.xml" target="files"/> + <target mode="plain" value="pages.xml"/> +</xsl:variable> + +<xsl:template match="files/pages/file[./extension = '.md']"> <entry handle="{./name}"> <xsl:choose> <xsl:when test="./extension = '.md'"> diff --git a/source/03_result/page.xsl b/source/03_result/page.xsl new file mode 100644 index 0000000..f6113f3 --- /dev/null +++ b/source/03_result/page.xsl @@ -0,0 +1,35 @@ +<?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:include href="[utility/master.xsl]"/> + +<xsl:variable name="meta"> + <datasource type="main" mode="iterate" source="target/02_data/pages.xml" target="page"/> + <datasource type="support" mode="full" source="source/00_content/meta.xml" target="meta"/> + <target mode="xpath" value="concat('pages/', xalan:nodeset($input)/datasource/page/entry/@handle)"/> +</xsl:variable> + +<xsl:template name="title-text"> + <xsl:value-of select="/datasource/page/entry/h1"/> +</xsl:template> + +<xsl:template match="page/entry"> + <div class="last article"> + <xsl:copy-of select="./*"/> + </div> +</xsl:template> + +</xsl:stylesheet> diff --git a/template/compiler/pages.xsl b/template/compiler/pages.xsl deleted file mode 100644 index dbde8c9..0000000 --- a/template/compiler/pages.xsl +++ /dev/null @@ -1,33 +0,0 @@ -<?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:include href="utility/context.xsl"/> - -<xsl:variable name="context" select="/data/meta"/> - -<xsl:variable name="datasources"> - <file name="pages.xml"/> -</xsl:variable> - -<xsl:template match="datasource[@name = 'pages.xml']/entry"> - <xsl:call-template name="generate_in_context"> - <xsl:with-param name="input" select="."/> - <xsl:with-param name="transformation" select="string('[template/output/page.xsl]')"/> - <xsl:with-param name="target" select="concat($context/target/output, '/pages/', @handle)"/> - </xsl:call-template> -</xsl:template> - -</xsl:stylesheet> diff --git a/template/output/page.xsl b/template/output/page.xsl deleted file mode 100644 index a271e4a..0000000 --- a/template/output/page.xsl +++ /dev/null @@ -1,23 +0,0 @@ -<?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="master.xsl"/> -<xsl:include href="[utility/date-time.xsl]"/> - -<xsl:template name="title-text"> - <xsl:value-of select="/entry/h1"/> @ /home/adrian -</xsl:template> - -<xsl:template match="data/entry"> - <div class="last article"> - <xsl:copy-of select="./*"/> - </div> -</xsl:template> - -</xsl:stylesheet> diff --git a/utility/context.xsl b/utility/context.xsl deleted file mode 100644 index 9dbfdc9..0000000 --- a/utility/context.xsl +++ /dev/null @@ -1,47 +0,0 @@ -<?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: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/generator.xsl b/utility/generator.xsl deleted file mode 100644 index eb65996..0000000 --- a/utility/generator.xsl +++ /dev/null @@ -1,22 +0,0 @@ -<?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:template name="generator"> - <xsl:param name="input"/> - <xsl:param name="transformation"/> - <xsl:param name="target"/> - - <xsl:copy-of select="InputXSLT:generate( - $input, - $transformation, - $target - )/self::generation"/> -</xsl:template> - -</xsl:stylesheet> diff --git a/template/output/master.xsl b/utility/master.xsl index fa00f9e..01bfd3c 100644 --- a/template/output/master.xsl +++ b/utility/master.xsl @@ -16,7 +16,9 @@ indent="yes" /> -<xsl:template match="data"> +<xsl:variable name="url" select="datasource/meta/url"/> + +<xsl:template match="/"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> @@ -24,8 +26,8 @@ <meta name="robots" content="all"/> <meta name="viewport" content="width=device-width,initial-scale=1.0"/> - <title><xsl:call-template name="title-text"/></title> - <link rel="stylesheet" type="text/css" href="{/meta/target/public}/main.css" /> + <title><xsl:call-template name="title-text"/> @ /home/adrian</title> + <link rel="stylesheet" type="text/css" href="{$url}/main.css" /> <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> </head> @@ -33,25 +35,25 @@ <div id="wrapper"> <div id="content"> <div id="nav_wrap"> - <h1><xsl:value-of select="/meta/title"/></h1> + <h1><xsl:value-of select="datasource/meta/title"/></h1> <ul> - <li><a href="{/meta/target/public}">Start</a></li> - <li><a href="{/meta/target/public}/archiv">Archiv</a></li> - <li><a href="{/meta/target/public}/projekte">Projekte</a></li> - <li><a href="{/meta/target/public}/seiten/kontakt">Kontakt</a></li> - <li class="last_item"><a href="{/meta/target/public}/rss">RSS</a></li> + <li><a href="{$url}">Start</a></li> + <li><a href="{$url}/archiv">Archiv</a></li> + <li><a href="{$url}/projekte">Projekte</a></li> + <li><a href="{$url}/seiten/kontakt">Kontakt</a></li> + <li class="last_item"><a href="{$url}/rss">RSS</a></li> </ul> </div> <div id="main"> - <xsl:apply-templates select="/entry"/> + <xsl:apply-templates /> </div> <div id="footer_wrap"> </div> <div id="last_line"> <a href="https://github.com/KnairdA/InputXSLT">Gemacht mit XSLT</a> <ul> - <li><a href="{/meta/target/public}/seiten/kontakt">Kontakt</a></li> - <li class="last_item"><a href="{/meta/target/public}/rss">RSS</a></li> + <li><a href="{$url}/seiten/kontakt">Kontakt</a></li> + <li class="last_item"><a href="{$url}/rss">RSS</a></li> </ul> </div> </div> @@ -60,5 +62,7 @@ </html> </xsl:template> +<xsl:template match="text()|@*"/> + </xsl:stylesheet> diff --git a/utility/reader.xsl b/utility/reader.xsl deleted file mode 100644 index 31d6fcc..0000000 --- a/utility/reader.xsl +++ /dev/null @@ -1,16 +0,0 @@ -<?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:template name="reader"> - <xsl:param name="path"/> - - <xsl:copy-of select="InputXSLT:read-file($path)/self::file/*"/> -</xsl:template> - -</xsl:stylesheet> diff --git a/utility/transformer.xsl b/utility/transformer.xsl deleted file mode 100644 index 0812f33..0000000 --- a/utility/transformer.xsl +++ /dev/null @@ -1,20 +0,0 @@ -<?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:template name="transformer"> - <xsl:param name="input"/> - <xsl:param name="transformation"/> - - <xsl:copy-of select="InputXSLT:transform( - $input, - $transformation - )/self::transformation/*"/> -</xsl:template> - -</xsl:stylesheet> diff --git a/utility/writer.xsl b/utility/writer.xsl deleted file mode 100644 index 42e9502..0000000 --- a/utility/writer.xsl +++ /dev/null @@ -1,20 +0,0 @@ -<?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:template name="writer"> - <xsl:param name="source"/> - <xsl:param name="target"/> - - <xsl:copy-of select="InputXSLT:write-file( - $target, - $source - )"/> -</xsl:template> - -</xsl:stylesheet> |