OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: recursive string escaping and custom namespace


i'm writing a stylesheet to convert docbook files into wiki text and at the 
moment i'm trying to write an extensible escaping function but having trouble 
with the custom namespace usage ... in other words, i want to take some 
arbitrary text (like in <para> tags which could be just about anything) and 
make sure i escape all the reserved wiki stylings

so if i had:
<para>blah lah __function blah</para>
i'd escape it to:
<para>blah lah %%__%%function blah</para>

rather than just calling out to replace-string for every such format 
('__' -> '%%__%%'), i'm trying to hide all of this wiki stuff in a sep file

i'm using this for the actual replace-string function:
http://aspn.activestate.com/ASPN/Cookbook/XSLT/Recipe/65426

and the attached .xsl is my attempt at writing a wiki escape function ... idea 
being i would use it like:
<xsl:template match="para">
    <xsl:call-template name="dokuwiki-escape">
        <xsl:with-param name="text" select="normalize-space(.)" />
    </xsl:call-template>
    ...
</xsl:template>

i know i'm missing something basic because i just started learning xsl 
yesterday ;x
-mike
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="text" indent="no" encoding="UTF-8" />
<xsl:strip-space elements="*" />

<xsl:include href="replace-string.xsl" />

<dokuwiki:stylesheet xmlns:dokuwiki="http://www.dokuwiki.org/"; version="1.0">

<dokuwiki:wiki_format>
	<dokuwiki:format>**</dokuwiki:format>
	<dokuwiki:format>//</dokuwiki:format>
	<dokuwiki:format>__</dokuwiki:format>
	<dokuwiki:format>''</dokuwiki:format>
	<dokuwiki:format>\\</dokuwiki:format>
</dokuwiki:wiki_format>

</dokuwiki:stylesheet>

<!--
escape dokuwiki style formatting by quoting all formats with %%:
	__foo -> %%__%%foo
-->
<xsl:template name="dokuwiki-escape">
	<xsl:param name="text" />
	<xsl:param name="idx">1</xsl:param>

	<xsl:variable name="new_text">
		<xsl:call-template name="replace-string">
			<xsl:with-param name="text" select="$text" />
			<xsl:with-param name="from" select="dokuwiki:format[$idx]" />
			<xsl:with-param name="to"   select="'%%' + dokuwiki:format[$idx] + '%%'" />
		</xsl:call-template>
	</xsl:variable>

	<xsl:choose>
		<xsl:when test="$idx &lt; count(dokuwiki:format)">
			<xsl:call-template name="dokuwiki-escape">
				<xsl:with-param name="text" select="$new_text" />
				<xsl:with-param name="idx"  select="$idx + 1" />
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$new_text" />
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>

PGP signature



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]