diff options
Diffstat (limited to 'source/02_data')
-rw-r--r-- | source/02_data/branches.xsl | 84 | ||||
-rw-r--r-- | source/02_data/leaves.xsl | 34 |
2 files changed, 118 insertions, 0 deletions
diff --git a/source/02_data/branches.xsl b/source/02_data/branches.xsl new file mode 100644 index 0000000..ce661cc --- /dev/null +++ b/source/02_data/branches.xsl @@ -0,0 +1,84 @@ +<?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="[utility/datasource.xsl]"/> + +<xsl:variable name="meta"> + <datasource type="main" mode="full" source="01_raw/tree.xml" target="tree"/> + <target mode="plain" value="branches.xml"/> +</xsl:variable> + +<xsl:template match="branch | leaf" mode="serialize"> + <xsl:apply-templates select="parent::branch" mode="serialize"/> + <xsl:text>/</xsl:text> + <xsl:value-of select="@name"/> +</xsl:template> + +<xsl:template match="@*|node()" mode="include"> + <xsl:copy> + <xsl:apply-templates select="@*|node()" mode="include"/> + </xsl:copy> +</xsl:template> + +<xsl:template match="leaf" mode="include"> + <xsl:apply-templates select="node()" mode="include"/> +</xsl:template> + +<xsl:template match="leaf" mode="digest"> + <node name="{@name}"> + <title> + <xsl:value-of select="title"/> + </title> + <digest size="{string-length(content/p[normalize-space(.)][1])}"> + <xsl:copy-of select="content/p[normalize-space(.)][1]/node()"/> + </digest> + </node> +</xsl:template> + +<xsl:template match="leaf"> + <xsl:variable name="name" select="@name"/> + + <xsl:if test="not(preceding-sibling::branch[@name = $name])"> + <xsl:apply-templates select="." mode="digest"/> + </xsl:if> +</xsl:template> + +<xsl:template match="branch" mode="digest"> + <xsl:variable name="name" select="@name"/> + + <xsl:apply-templates select="following-sibling::leaf[@name = $name]" mode="digest"/> +</xsl:template> + +<xsl:template match="branch"> + <xsl:variable name="path"> + <xsl:apply-templates select="." mode="serialize"/> + </xsl:variable> + + <entry handle="{$path}"> + <xsl:variable name="name" select="@name"/> + + <payload> + <xsl:apply-templates select="following-sibling::leaf[@name = $name]" mode="include"/> + </payload> + + <branches> + <xsl:apply-templates select="branch" mode="digest"/> + </branches> + + <leaves> + <xsl:apply-templates select="leaf"/> + </leaves> + </entry> +</xsl:template> + +<xsl:template match="tree"> + <xsl:apply-templates select="//branch"/> +</xsl:template> + +</xsl:stylesheet> diff --git a/source/02_data/leaves.xsl b/source/02_data/leaves.xsl new file mode 100644 index 0000000..81ba8f3 --- /dev/null +++ b/source/02_data/leaves.xsl @@ -0,0 +1,34 @@ +<?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="[utility/datasource.xsl]"/> + +<xsl:variable name="meta"> + <datasource type="main" mode="full" source="01_raw/tree.xml" target="tree"/> + <target mode="plain" value="leaves.xml"/> +</xsl:variable> + +<xsl:template match="branch | leaf" mode="serialize"> + <xsl:apply-templates select="parent::branch" mode="serialize"/> + <xsl:text>/</xsl:text> + <xsl:value-of select="@name"/> +</xsl:template> + +<xsl:template match="tree//leaf[not(preceding-sibling::branch[@name = current()/@name])]"> + <xsl:variable name="path"> + <xsl:apply-templates select="." mode="serialize"/> + </xsl:variable> + + <entry handle="{$path}"> + <xsl:copy-of select="title"/> + <xsl:copy-of select="content"/> + </entry> +</xsl:template> + +</xsl:stylesheet> |