Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
332 lines (295 sloc) 10.9 KB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xslt [
<!--Used to control code intenting -->
<!ENTITY nl "&#xa;">
<!ENTITY tab " ">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:strip-space elements="*"/>
<xsl:param name="mode" />
<xsl:template match="/">
<xsl:apply-templates select="//top" />
<xsl:apply-templates select="//function" />
<xsl:text disable-output-escaping="yes">
end # GeneratedDriver
end # Client
end # Selenium
</xsl:text>
</xsl:template>
<!--********************
TOP
***************-->
<xsl:template match="top">
<xsl:text disable-output-escaping="yes">
# Copyright 2006 ThoughtWorks, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -----------------
# Original code by Aslak Hellesoy and Darren Hobbs
# This file has been automatically generated via XSL
# -----------------
# </xsl:text>
<xsl:apply-templates>
<xsl:with-param name="replace-string">&nl;# </xsl:with-param>
</xsl:apply-templates>
<xsl:text disable-output-escaping="yes"><![CDATA[
module Selenium
module Client
module GeneratedDriver
]]>
</xsl:text>
</xsl:template>
<xsl:template match="comment">
<xsl:text>&nl;&tab;&tab;# </xsl:text>
<xsl:apply-templates>
<xsl:with-param name="replace-string">&nl;&tab;&tab;# </xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="node()|@*" >
<xsl:param name="replace-string" />
<xsl:copy>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="text()">
<xsl:param name="replace-string" />
<xsl:call-template name="search-and-replace">
<xsl:with-param name="input"><xsl:value-of select='.' /></xsl:with-param>
<xsl:with-param name="search-string"><xsl:text>&nl;</xsl:text></xsl:with-param>
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="b|strong">
<xsl:param name="replace-string" />
<xsl:element name="b">
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="code|tt">
<xsl:param name="replace-string" />
<xsl:element name="tt">
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="em|i">
<xsl:param name="replace-string" />
<xsl:element name="em">
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="h3">
<xsl:param name="replace-string" />
<xsl:text>===</xsl:text>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="li">
<xsl:param name="replace-string" />
<xsl:choose>
<xsl:when test="local-name(..) = 'ul'">
<xsl:text>*&tab;</xsl:text>
</xsl:when>
<xsl:when test="local-name(..) = 'ol'">
<xsl:value-of select="position()"/><xsl:text>. </xsl:text>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
<xsl:value-of select="$replace-string" />
</xsl:template>
<xsl:template match="ul|ol|dl">
<xsl:param name="replace-string" />
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /><!--<xsl:text>&tab;</xsl:text>--></xsl:with-param>
</xsl:apply-templates>
<xsl:value-of select="$replace-string" />
</xsl:template>
<xsl:template match="p">
<xsl:param name="replace-string" />
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
<xsl:value-of select="$replace-string" />
</xsl:template>
<xsl:template match="a|blockquote">
<xsl:param name="replace-string" />
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="dt">
<xsl:param name="replace-string" />
<xsl:text>*&tab;</xsl:text>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /></xsl:with-param>
</xsl:apply-templates>
<xsl:text>::</xsl:text>
</xsl:template>
<xsl:template match="dd">
<xsl:param name="replace-string" />
<xsl:value-of select="$replace-string" />
<xsl:text>&tab;</xsl:text>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="replace-string"><xsl:value-of select="$replace-string" /><xsl:text>&tab;</xsl:text></xsl:with-param>
</xsl:apply-templates>
<xsl:value-of select="$replace-string" />
</xsl:template>
<!--****************
FUNCTION
******************-->
<xsl:template match="function">
<!-- Doc -->
<xsl:apply-templates select="comment" />
<xsl:text>&nl;&tab;&tab;#</xsl:text>
<xsl:apply-templates select="param" mode="comment" />
<xsl:text>&nl;&tab;&tab;def </xsl:text>
<xsl:call-template name="underscorify">
<xsl:with-param name="input"><xsl:value-of select="@name" /></xsl:with-param>
</xsl:call-template>
<!-- Params -->
<xsl:text>(</xsl:text>
<xsl:apply-templates select="param" mode="declaration" />
<xsl:text>)&nl;&tab;&tab;&tab;</xsl:text>
<xsl:if test="count(./return) = 0">
<xsl:text>remote_control_command</xsl:text>
</xsl:if>
<xsl:apply-templates select="return" mode="implementation" />
<xsl:text>("</xsl:text>
<xsl:value-of select="@name" />
<xsl:text>", [</xsl:text>
<xsl:apply-templates select="param" mode="implementation" />
<xsl:text>])&nl;&tab;&tab;end&nl;&nl;</xsl:text>
</xsl:template>
<!--*****************
RETURN
*******************-->
<xsl:template name="procMethod">
<xsl:param name="type" />
<xsl:choose>
<xsl:when test="$type='string'">
<xsl:text>string_command</xsl:text>
</xsl:when>
<xsl:when test="$type='number'">
<xsl:text>number_command</xsl:text>
</xsl:when>
<xsl:when test="$type='boolean'">
<xsl:text>boolean_command</xsl:text>
</xsl:when>
<xsl:when test="$type='string[]'">
<xsl:text>string_array_command</xsl:text>
</xsl:when>
<xsl:when test="$type='number[]'">
<xsl:text>number_array_command</xsl:text>
</xsl:when>
<xsl:when test="$type='boolean[]'">
<xsl:text>boolean_array_command</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">returntype is invalid: <xsl:value-of select="$type"/></xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- In the function implementation, add "return" keyword, casting to correct type -->
<xsl:template match="return" mode="implementation">
<xsl:text>return </xsl:text>
<xsl:call-template name="procMethod">
<xsl:with-param name="type"><xsl:value-of select="@type" /></xsl:with-param>
</xsl:call-template>
</xsl:template>
<!-- In the RDoc, add the <returns> tag -->
<xsl:template match="return" mode="comment">
<xsl:text>&nl;&tab;&tab;/// &lt;returns&gt;</xsl:text>
<xsl:call-template name="search-and-replace">
<xsl:with-param name="input"><xsl:value-of select="."/></xsl:with-param>
<xsl:with-param name="search-string"><xsl:text>&nl;</xsl:text></xsl:with-param>
<xsl:with-param name="replace-string">&nl;&tab;&tab;/// </xsl:with-param>
</xsl:call-template>
<xsl:text>&lt;/returns&gt;</xsl:text>
</xsl:template>
<!-- In the RDoc, add the <param> tag -->
<xsl:template match="param" mode="comment">
<xsl:text>&nl;&tab;&tab;# '</xsl:text>
<xsl:value-of select="@name" />
<xsl:text>' is </xsl:text>
<xsl:apply-templates />
</xsl:template>
<!-- In the function declaration, specify all String parameters -->
<xsl:template match="param" mode="declaration">
<xsl:value-of select="@name" />
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:template>
<!-- In the function implementation, add String parameters to array -->
<xsl:template match="param" mode="implementation">
<xsl:value-of select="@name" />
<xsl:text>,</xsl:text>
</xsl:template>
<xsl:template name="search-and-replace">
<xsl:param name="input"/>
<xsl:param name="search-string"/>
<xsl:param name="replace-string"/>
<xsl:choose>
<!-- See if the input contains the search string -->
<xsl:when test="$search-string and
contains($input,$search-string)">
<!-- If so, then concatenate the substring before the search
string to the replacement string and to the result of
recursively applying this template to the remaining substring.
-->
<xsl:value-of
select="substring-before($input,$search-string)"/>
<xsl:value-of select="$replace-string"/>
<xsl:call-template name="search-and-replace">
<xsl:with-param name="input"
select="substring-after($input,$search-string)"/>
<xsl:with-param name="search-string"
select="$search-string"/>
<xsl:with-param name="replace-string"
select="$replace-string"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- There are no more occurrences of the search string so
just return the current input string -->
<xsl:value-of select="$input"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="underscorify">
<xsl:param name="input" />
<xsl:if test="$input">
<xsl:variable name="first-char" select="substring($input, 1, 1)"/>
<xsl:variable name="lower-first-char" select="translate($first-char, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
<xsl:if test="$first-char != $lower-first-char">
<xsl:text>_</xsl:text>
</xsl:if>
<xsl:value-of select="$lower-first-char"/>
<xsl:call-template name="underscorify">
<xsl:with-param name="input" select="substring($input, 2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>