diff options
Diffstat (limited to 'bindings/python/gtkdoc-to-swig.xsl')
-rw-r--r-- | bindings/python/gtkdoc-to-swig.xsl | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bindings/python/gtkdoc-to-swig.xsl b/bindings/python/gtkdoc-to-swig.xsl new file mode 100644 index 0000000..520ceb7 --- /dev/null +++ b/bindings/python/gtkdoc-to-swig.xsl @@ -0,0 +1,54 @@ +<?xml version="1.0"?> + +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> + <xsl:output + encoding="ASCII" + method="text"/> + + <xsl:template match="/"> + <xsl:for-each select="//refsect2[./title/anchor/@role='function']"> + <xsl:text>%feature("docstring", "</xsl:text> + <xsl:call-template name="CleanQuotes"> + <xsl:with-param name="body" select="para"/> + </xsl:call-template> + <xsl:if test="variablelist[@role='params']"> + <xsl:text> Parameters </xsl:text> + <xsl:for-each select="variablelist[@role='params']/varlistentry"> + <xsl:call-template name="CleanQuotes"> + <!-- We're going to remove the nbsp chars as we're rendering to python docstrings --> + <xsl:with-param name="body" select="translate(term,' ','')"/> + </xsl:call-template> + <xsl:call-template name="CleanQuotes"> + <xsl:with-param name="body" select="translate(listitem,' ','')"/> + </xsl:call-template> + </xsl:for-each> + </xsl:if> + <xsl:text>") </xsl:text> + <xsl:value-of select="substring-before(./title[./anchor/@role='function'],' ')"/> + <xsl:text>; </xsl:text> + </xsl:for-each> + </xsl:template> + + <!-- recursive cleaner, matches string to first quote then recurses to + process the rest + Note how it uses a When to test if the termination condition of no + quotes has been reached + --> + + + <xsl:template name="CleanQuotes"><xsl:param name="body"/> + <xsl:choose> + <xsl:when test="contains($body, '"')"> + <xsl:value-of select="substring-before($body, '"')" /> + <xsl:text>\"</xsl:text> + <xsl:call-template name="CleanQuotes"> + <xsl:with-param name="body" select="substring-after($body,'"')"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$body"/><!-- finished recursing --> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + +</xsl:stylesheet> |