1
0
Fork 0

Stupidly simple serialization

This will be improved upon in the future; it exists in the spirit of weaving
in literate programming.
master
Mike Gerwitz 2015-04-14 14:16:10 -04:00
parent 530407e05d
commit 106f96c498
1 changed files with 73 additions and 1 deletions

View File

@ -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>