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,
|
||||
$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><</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>
|
||||
|
|
Loading…
Reference in New Issue