Last active
May 13, 2021 23:53
-
-
Save blaggacao/e7ba05c7b4aa36317046ceb843cbed9f to your computer and use it in GitHub Desktop.
Odoo Studio to Python XSLT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org"> | |
<xsl:template name="printIndented"> | |
<xsl:param name="text" /> | |
<xsl:param name="indent" /> | |
<xsl:if test="$text"> | |
<xsl:value-of select="$indent" /> | |
<xsl:variable name="thisLine" select="substring-before($text, ' ')" /> | |
<xsl:choose> | |
<xsl:when test="$thisLine"><!-- $text contains at least one newline --> | |
<!-- print this line --> | |
<xsl:value-of select="concat($thisLine, ' ')" /> | |
<!-- and recurse to process the rest --> | |
<xsl:call-template name="printIndented"> | |
<xsl:with-param name="text" select="substring-after($text, ' ')" /> | |
<xsl:with-param name="indent" select="$indent" /> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$text" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:if> | |
</xsl:template> | |
<xsl:template name="string-replace-all"> | |
<xsl:param name="text" /> | |
<xsl:param name="replace" /> | |
<xsl:param name="by" /> | |
<xsl:choose> | |
<xsl:when test="$text = '' or $replace = ''or not($replace)" > | |
<!-- Prevent this routine from hanging --> | |
<xsl:value-of select="$text" /> | |
</xsl:when> | |
<xsl:when test="contains($text, $replace)"> | |
<xsl:value-of select="substring-before($text,$replace)" /> | |
<xsl:value-of select="$by" /> | |
<xsl:call-template name="string-replace-all"> | |
<xsl:with-param name="text" select="substring-after($text,$replace)" /> | |
<xsl:with-param name="replace" select="$replace" /> | |
<xsl:with-param name="by" select="$by" /> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$text" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template match="/"> | |
<xsl:variable name="Upper">ABCDEFGHIJKLMNOPQRSTUVQXYZ</xsl:variable> | |
<xsl:variable name="Lower">abcdefghijklmnopqrstuvwxyz</xsl:variable> | |
    # Python Code, please review and adapt | |
<xsl:for-each select="odoo/record"> | |
    <xsl:value-of select="substring(field[@name='name'],10,string-length(field[@name='name']))"/> = fields.<xsl:value-of select="translate(substring(field[@name='ttype'],1,1),$Lower,$Upper)"/><xsl:value-of select="substring(field[@name='ttype'],2,string-length(field[@name='ttype']))"/>(<xsl:if test="field[@name='relation'] != ''"> | |
        comodel_name="<xsl:value-of select="field[@name='relation']"/>",</xsl:if> | |
        string="<xsl:value-of select="field[@name='field_description']"/>", | |
        domain="<xsl:value-of select="field[@name='domain']"/>", | |
        copied=<xsl:value-of select="field[@name='copied']/@eval"/>, | |
        groups=<xsl:value-of select="field[@name='groups']/@eval"/>,<xsl:if test="field[@name='index']/@eval != 'False'"> | |
        index=<xsl:value-of select="field[@name='index']/@eval"/>,</xsl:if><xsl:if test="field[@name='readonly']/@eval != 'False'"> | |
        readonly=<xsl:value-of select="field[@name='readonly']/@eval"/>,</xsl:if><xsl:if test="field[@name='required']/@eval != 'False'"> | |
        required=<xsl:value-of select="field[@name='required']/@eval"/>,</xsl:if><xsl:if test="field[@name='selection']/@eval != 'False'"> | |
        selection=<xsl:value-of select="field[@name='selection']"/>,</xsl:if><xsl:if test="field[@name='store']/@eval != 'False'"> | |
        store=<xsl:value-of select="field[@name='store']/@eval"/>,</xsl:if><xsl:if test="field[@name='track_visibility']/@eval != 'False'"> | |
        track_visibility=<xsl:value-of select="field[@name='track_visibility']/@eval"/>,</xsl:if><xsl:if test="field[@name='track_visibility']/@eval != 'False'"> | |
        translate=<xsl:value-of select="field[@name='translate']/@eval"/>,</xsl:if><xsl:if test="field[@name='related']/@eval != 'False'"> | |
        related="<xsl:value-of select="field[@name='related']"/>",</xsl:if><xsl:if test="field[@name='compute'] != ''"> | |
        compute="_compute_<xsl:value-of select="substring(field[@name='name'],10,string-length(field[@name='name']))"/>",</xsl:if><xsl:if test="field[@name='help'] != ''"> | |
        help="""<xsl:value-of select="field[@name='help']"/>""",</xsl:if> | |
) | |
<xsl:if test="field[@name='compute'] != ''"> | |
def _compute_<xsl:value-of select="substring(field[@name='name'],10,string-length(field[@name='name']))"/>(self): | |
<xsl:variable name="without-studio-prefix"> | |
<xsl:call-template name="string-replace-all"> | |
<xsl:with-param name="text" select="field[@name='compute']" /> | |
<xsl:with-param name="replace">x_studio_</xsl:with-param> | |
<xsl:with-param name="by"></xsl:with-param> | |
</xsl:call-template> | |
</xsl:variable> | |
<xsl:call-template name="printIndented"> | |
<xsl:with-param name="indent">        </xsl:with-param> | |
<xsl:with-param name="text" | |
><xsl:value-of select="$without-studio-prefix" /> | |
</xsl:with-param> | |
</xsl:call-template> | |
<xsl:text>
</xsl:text> | |
</xsl:if> | |
</xsl:for-each> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment