Stupidly simple serialization
This will be improved upon in the future; it exists in the spirit of weaving in literate programming.master
parent
530407e05d
commit
106f96c498
|
@ -70,12 +70,17 @@
|
||||||
$xt:nl,
|
$xt:nl,
|
||||||
$doc,
|
$doc,
|
||||||
$xt:nl,
|
$xt:nl,
|
||||||
|
'@verbatim',
|
||||||
|
$xt:nl,
|
||||||
|
xt:serialize( . ),
|
||||||
|
$xt:nl,
|
||||||
|
'@end verbatim',
|
||||||
|
$xt:nl,
|
||||||
'@end deffn',
|
'@end deffn',
|
||||||
$xt:nl)" />
|
$xt:nl)" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Escape `at' symbols in matches.
|
Escape `at' symbols in matches.
|
||||||
|
|
||||||
|
@ -126,6 +131,12 @@
|
||||||
$xt:nl,
|
$xt:nl,
|
||||||
$doc,
|
$doc,
|
||||||
$xt:nl,
|
$xt:nl,
|
||||||
|
'@verbatim',
|
||||||
|
$xt:nl,
|
||||||
|
xt:serialize( . ),
|
||||||
|
$xt:nl,
|
||||||
|
'@end verbatim',
|
||||||
|
$xt:nl,
|
||||||
'@end deftypefn',
|
'@end deftypefn',
|
||||||
$xt:nl)" />
|
$xt:nl)" />
|
||||||
</template>
|
</template>
|
||||||
|
@ -200,4 +211,65 @@
|
||||||
match="*|@*|text()|comment()">
|
match="*|@*|text()|comment()">
|
||||||
</template>
|
</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><</text>
|
||||||
|
<value-of select="name()" />
|
||||||
|
|
||||||
|
<apply-templates mode="xt:serialize"
|
||||||
|
select="@*" />
|
||||||
|
|
||||||
|
<choose>
|
||||||
|
<when test="node()">
|
||||||
|
<text>></text>
|
||||||
|
<apply-templates mode="xt:serialize" />
|
||||||
|
<sequence select="concat('</', name(), '>' )" />
|
||||||
|
</when>
|
||||||
|
|
||||||
|
<otherwise>
|
||||||
|
<text> /></text>
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
<template match="@*" mode="xt:serialize">
|
||||||
|
<sequence select="concat(
|
||||||
|
' ',
|
||||||
|
name(),
|
||||||
|
'="',
|
||||||
|
normalize-space( . ),
|
||||||
|
'"' )" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
<template match="text()" mode="xt:serialize">
|
||||||
|
<sequence select="." />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
<template match="comment()" mode="xt:serialize">
|
||||||
|
<sequence select="concat( '<!--', ., '-->' )" />
|
||||||
|
</template>
|
||||||
|
|
||||||
</stylesheet>
|
</stylesheet>
|
||||||
|
|
Loading…
Reference in New Issue