Mike Gerwitz

Activist for User Freedom

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitm@lovullo.com>2015-04-14 14:16:10 -0400
committerMike Gerwitz <gerwitm@lovullo.com>2015-04-14 14:22:26 -0400
commit106f96c498072615ed013d890e31cb21aa9e5201 (patch)
treeb0f857079b49afbb6c0c798fa3a158f138c9ab15
parent530407e05dafaa0ace9936bb3b3a3b2b7f8c60f1 (diff)
downloadliterate-xsl-106f96c498072615ed013d890e31cb21aa9e5201.tar.gz
literate-xsl-106f96c498072615ed013d890e31cb21aa9e5201.tar.bz2
literate-xsl-106f96c498072615ed013d890e31cb21aa9e5201.zip
Stupidly simple serialization
This will be improved upon in the future; it exists in the spirit of weaving in literate programming.
-rw-r--r--src/xsltexi.xsl74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/xsltexi.xsl b/src/xsltexi.xsl
index c81965f..b62527f 100644
--- a/src/xsltexi.xsl
+++ b/src/xsltexi.xsl
@@ -70,12 +70,17 @@
$xt:nl,
$doc,
$xt:nl,
+ '@verbatim',
+ $xt:nl,
+ xt:serialize( . ),
+ $xt:nl,
+ '@end verbatim',
+ $xt:nl,
'@end deffn',
$xt:nl)" />
</template>
-
<!--
Escape `at' symbols in matches.
@@ -126,6 +131,12 @@
$xt:nl,
$doc,
$xt:nl,
+ '@verbatim',
+ $xt:nl,
+ xt:serialize( . ),
+ $xt:nl,
+ '@end verbatim',
+ $xt:nl,
'@end deftypefn',
$xt:nl)" />
</template>
@@ -200,4 +211,65 @@
match="*|@*|text()|comment()">
</template>
+
+<!--
+ Serialization templates
+
+
+ This is very basic; it will be improved upon in the future.
+-->
+
+<function name="xt:serialize" as="xs:string">
+ <param name="context" />
+
+ <variable name="result">
+ <apply-templates mode="xt:serialize"
+ select="$context" />
+ </variable>
+
+ <value-of select="$result" separator="" />
+</function>
+
+
+<template mode="xt:serialize"
+ match="element()">
+ <text>&lt;</text>
+ <value-of select="name()" />
+
+ <apply-templates mode="xt:serialize"
+ select="@*" />
+
+ <choose>
+ <when test="node()">
+ <text>&gt;</text>
+ <apply-templates mode="xt:serialize" />
+ <sequence select="concat('&lt;/', name(), '&gt;' )" />
+ </when>
+
+ <otherwise>
+ <text> /&gt;</text>
+ </otherwise>
+ </choose>
+</template>
+
+
+<template match="@*" mode="xt:serialize">
+ <sequence select="concat(
+ ' ',
+ name(),
+ '=&quot;',
+ normalize-space( . ),
+ '&quot;' )" />
+</template>
+
+
+<template match="text()" mode="xt:serialize">
+ <sequence select="." />
+</template>
+
+
+<template match="comment()" mode="xt:serialize">
+ <sequence select="concat( '&lt;!--', ., '--&gt;' )" />
+</template>
+
</stylesheet>