الخميس، 24 يوليو 2014

Language XSLT (Android)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:string="http://www.getsymphony.com/functions"
>
  <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes" />
  <xsl:strip-space elements="*"/>
  <xsl:param name="fname">D:\1_6_2014\Android\camera\res\layout\mainpage.xml</xsl:param>


  <xsl:template match="/*">

    <xsl:apply-templates select="Member_NamespaceDeclaration" mode="package"/>
    <xsl:text>import edu.icpmd.*;</xsl:text>
    <xsl:text>&#xa;</xsl:text>
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="Member_UsingDeclaration">
    <xsl:text>import </xsl:text>
    <xsl:value-of select="concat(@Namespace,';')"/>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="Member_NamespaceDeclaration" mode="package">
    <xsl:text>package </xsl:text>
    <xsl:value-of select="concat(concat('edu.icpmd.',@Name),';')"/>
    <xsl:text>&#xa;</xsl:text>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>

  <xsl:template match="Member_NamespaceDeclaration">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="token">
    <xsl:choose>
      <xsl:when test="@value ='{'">
        <xsl:choose>
          <xsl:when test="parent::Member_NamespaceDeclaration">
            <xsl:text>&#xa;</xsl:text>
          </xsl:when>

          <xsl:when test="parent::Member_TypeDeclaration and ../@ClassType='Class'">
            <xsl:text>&#xa;</xsl:text>{<xsl:text>&#xa;</xsl:text>

            <xsl:call-template name="controls_def"/>

            <xsl:text>
@Override
protected void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);
</xsl:text>

            <xsl:text>setContentView(R.layout.</xsl:text>
            <xsl:value-of select="concat(translate(../@Name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),')')" />

            <xsl:text>;</xsl:text>
            <xsl:call-template name="controls"/>
            <xsl:text>
}&#xa;&#xa;</xsl:text>
          </xsl:when>

          <xsl:otherwise>
            <xsl:text>&#xa;</xsl:text>{<xsl:text>&#xa;</xsl:text>


          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>

      <xsl:when test="@value ='}'">
        <xsl:choose>
          <xsl:when test="parent::Member_NamespaceDeclaration">
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>&#xa;</xsl:text>}<xsl:text>&#xa;</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>

      <xsl:when test="@value ='.'">
        <xsl:choose>
          <xsl:when test="parent::Import_MemberType">
          </xsl:when>
          <xsl:otherwise>.</xsl:otherwise>
        </xsl:choose>
      </xsl:when>

      <xsl:when test="@value =':'">
        <xsl:choose>
          <xsl:when test="parent::Member_TypeDeclaration">
            <xsl:value-of select="concat(' extends',' ')"/>
          </xsl:when>
          <xsl:otherwise>:</xsl:otherwise>
        </xsl:choose>
      </xsl:when>

      <xsl:when test="@value =';'">
        ;<xsl:text>&#xa;</xsl:text>
      </xsl:when>
      <xsl:when test="@value ='='">=</xsl:when>
      <xsl:when test="@value =','">
        <xsl:choose>
          <xsl:when xmlns:android="http://schemas.android.com/apk/res/android" test="document($fname)//@android:onClick =../@Name">
            <xsl:text>View arg0</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            ,
          </xsl:otherwise>
        </xsl:choose>

      </xsl:when>
      <xsl:when test="@value ='('">(</xsl:when>
      <xsl:when test="@value =')'">)</xsl:when>
      <xsl:otherwise></xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="Member_TypeDeclaration">
    <xsl:choose>
      <xsl:when test="@ClassType='Class'">
        <!--
<xsl:value-of select="concat(concat(concat(Modifier_CSharpModifierToken/@Modifier,' class '),@Name),concat(' extends ' , BaseType_SimpleType/@Identifier))"/>
-->
      </xsl:when>
      <xsl:otherwise></xsl:otherwise>
    </xsl:choose>


    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="TypeMember_ConstructorDeclaration">
    <!--
<xsl:value-of select="concat(concat(concat(Modifier_CSharpModifierToken/@Modifier,' '),' '), Identifier_Identifier/@Name)"/>
-->
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="TypeMember_MethodDeclaration">
    <!--
<xsl:value-of select="concat(concat(concat(Modifier_CSharpModifierToken/@Modifier,' '),' '), Identifier_Identifier/@Name)"/>
-->

    <xsl:apply-templates />

  </xsl:template>



  <xsl:template match="Modifier_CSharpModifierToken">
    <xsl:choose>
      <xsl:when xmlns:android="http://schemas.android.com/apk/res/android" test="document($fname)//@android:onClick =../@Name">
        <xsl:value-of select="translate(concat(translate(@Modifier,'Private','public'),' '),'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
      </xsl:when>
      <xsl:when xmlns:android="http://schemas.android.com/apk/res/android" test="document($fname)//@android:onClick !=../@Name">
        <xsl:value-of select="translate(concat(@Modifier,' '),'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>

      </xsl:when>
    </xsl:choose>

  </xsl:template>

  <xsl:template match="class_CSharpTokenNode">
    <xsl:value-of select="concat('class',' ')"/>
  </xsl:template>

  <xsl:template match="BaseType_SimpleType">

    <xsl:choose>
      <xsl:when test="@Identifier='PhoneApplicationPage'">
        <xsl:text>Activity</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@Name"/>

      </xsl:otherwise>
    </xsl:choose>
    <!--<xsl:value-of select="concat(' ', @Identifier)"/>-->
  </xsl:template>

  <xsl:template match="Identifier_Identifier">
    <xsl:choose>
      <xsl:when test="parent::Member_NamespaceDeclaration">
      </xsl:when>
      <xsl:when test="@Name='Text'">
        <xsl:text>getText().toString()</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@Name"/>

      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="Type_PrimitiveType">
    <xsl:value-of select="concat(@Keyword,' ')"/>

  </xsl:template>

  <xsl:template match="Variable_VariableInitializer">
    <xsl:value-of select="@Name"/>
  </xsl:template>
  <xsl:template match="Left_IdentifierExpression">
    <xsl:value-of select="@Identifier"/>
  </xsl:template>

  <xsl:template match="Parameter_ParameterDeclaration">
    <xsl:choose>
      <xsl:when xmlns:android="http://schemas.android.com/apk/res/android" test="document($fname)//@android:onClick =../@Name">

      </xsl:when>
      <xsl:when xmlns:android="http://schemas.android.com/apk/res/android" test="document($fname)//@android:onClick !=../@Name">
        <xsl:apply-templates/>
      </xsl:when>
    </xsl:choose>
    <!--
<xsl:choose>
<xsl:when test="$event_name=string(.)">
<xsl:variable name="fevent" select="1" />

<xsl:call-template name="controls_event">
<xsl:with-param name="event_name" select="../@Name"/>
</xsl:call-template>-->
    <!--<xsl:value-of select="$fevent"/>-->
    <!--<xsl:if test="$fevent=1">
<xsl:apply-templates/>
</xsl:if>-->
  </xsl:template>


  <xsl:template match="Right_MemberReferenceExpression">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="Statement_ExpressionStatement">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="Expression_AssignmentExpression">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="Type_SimpleType">
    <xsl:value-of select="concat(@Identifier, ' ')"/>
  </xsl:template>



  <xsl:template match="Statement_VariableDeclarationStatement">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="ICPMD_Webview_load">
    <xsl:text>&#xa;</xsl:text>
    <xsl:text>functions.webview_load(</xsl:text>
    <xsl:value-of select="mywebview"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="url"/>
    <xsl:text>);</xsl:text>
    <xsl:text>&#xa;</xsl:text>

  </xsl:template>

  <!--
<xsl:template match="*/text()[normalize-space()]">
    <xsl:value-of select="normalize-space()"/>
</xsl:template>

<xsl:template match="*/text()[not(normalize-space())]" />-->

  <xsl:template name="controls_def">

    <xsl:for-each xmlns:android="http://schemas.android.com/apk/res/android" select="document($fname)//@android:id">
      <xsl:value-of select="concat(name(..),' ')"/>
      <xsl:value-of select="concat(substring(string(.),6),';')"/>
      <xsl:text>&#xa;</xsl:text>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="controls">
    <xsl:text>&#xa;</xsl:text>
    <xsl:for-each xmlns:android="http://schemas.android.com/apk/res/android" select="document($fname)//@android:id">

      <xsl:value-of select="concat(substring(string(.),6),' = ')"/>
      <xsl:value-of select="concat('(',name(..),') ')"/>
      <xsl:value-of select="concat('findViewById(R.id.',substring(string(.),6),')',';') "/>

      <xsl:text>&#xa;</xsl:text>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="ICPMD_Camera_app_open">
    <xsl:text>functions.camera_app_open(this,0);</xsl:text>
  </xsl:template>


  <xsl:template match="ICPMD_Camera_app_result">
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    functions.camera_app_result(this, resultCode, <xsl:value-of select="myimage"/>, data);


    }



  </xsl:template>

</xsl:stylesheet>

UI XSLT (P) - from Abstract Model to Android

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" >

  <xsl:template match="/">
    <xsl:apply-templates select="page"/>
  </xsl:template>
  <xsl:template match="page">
    <xsl:element name="LinearLayout">
      <xsl:attribute name="tools:context">
        <xsl:value-of select="concat('.',substring-after(class,'.'))"/>
      </xsl:attribute>
      <xsl:attribute name="android:layout_width">
        <xsl:text>match_parent</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="android:layout_height">
        <xsl:text>match_parent</xsl:text>
      </xsl:attribute>

      <xsl:if test="orientation/@orientation">
        <xsl:choose>
          <xsl:when test="orientation/@orientation='Portrait'">
            <xsl:attribute name="android:orientation">
              <xsl:text>vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="orientation/@orientation='Landscape'">
            <xsl:attribute name="android:orientation">
              <xsl:text>horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>

      </xsl:if>

      <xsl:apply-templates select="node()"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="gridlayout">
    <xsl:element name="GridLayout" >
      <xsl:if test="@name!=''">
        <xsl:attribute name="android:id">
          <xsl:value-of select="concat('@+id/',@name)"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:attribute name="android:rowCount">
        <xsl:value-of select="@rows"/>
      </xsl:attribute >

      <xsl:attribute name="android:columnCount">
        <xsl:value-of select="@columns"/>
      </xsl:attribute >

      <xsl:if test="@row">
        <xsl:attribute name="android:layout_row">
          <xsl:value-of select="@row"/>
        </xsl:attribute>

      </xsl:if>
      <xsl:if test="@height!=''">
        <xsl:attribute name="android:layout_height">
          <xsl:value-of select="concat(@height,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width!=''">
        <xsl:attribute name="android:layout_width">
          <xsl:value-of select="concat(@width,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height=''">
        <xsl:attribute name="android:layout_height">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width=''">
        <xsl:attribute name="android:layout_width">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>

      <xsl:apply-templates select="node()"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="linearlayout">
    <xsl:element name="LinearLayout">
      <xsl:if test="@name!=''">
        <xsl:attribute name="android:id">
          <xsl:value-of select="concat('@+id/',@name)"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@row">
        <xsl:attribute name="android:layout_row">
          <xsl:value-of select="@row"/>
        </xsl:attribute>

      </xsl:if>
      <xsl:if test="@height!=''">
        <xsl:attribute name="android:layout_height">
          <xsl:value-of select="concat(@height,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width!=''">
        <xsl:attribute name="android:layout_width">
          <xsl:value-of select="concat(@width,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height=''">
        <xsl:attribute name="android:layout_height">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width=''">
        <xsl:attribute name="android:layout_width">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>

      <xsl:apply-templates select="node()"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="label">
    <xsl:element name="TextView">
      <xsl:if test="@name!=''">
        <xsl:attribute name="android:id">
          <xsl:value-of select="concat('@+id/',@name)"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:attribute name="android:text">
        <xsl:value-of select="@text"/>
      </xsl:attribute>
      <xsl:if test="@height!=''">
        <xsl:attribute name="android:layout_height">
          <xsl:value-of select="concat(@height,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width!=''">
        <xsl:attribute name="android:layout_width">
          <xsl:value-of select="concat(@width,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height=''">
        <xsl:attribute name="android:layout_height">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width=''">
        <xsl:attribute name="android:layout_width">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>

      <xsl:if test="@valign">
        <xsl:choose>
          <xsl:when test="@valign='Bottom'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>bottom</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Center'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>center_vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Stretch'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>fill_vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Top'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>top</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>

      <xsl:if test="@halign">
        <xsl:choose>
          <xsl:when test="@halign='Left'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>left</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Center'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>center_horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Stretch'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>fill_horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Right'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>right</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>

    </xsl:element>

  </xsl:template>

  <xsl:template match="textbox">
    <xsl:element name="EditText">
      <xsl:if test="@name!=''">
        <xsl:attribute name="android:id">
          <xsl:value-of select="concat('@+id/',@name)"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:attribute name="android:text">
        <xsl:value-of select="@text"/>
      </xsl:attribute>
      <xsl:if test="@height!=''">
        <xsl:attribute name="android:layout_height">
          <xsl:value-of select="concat(@height,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width!=''">
        <xsl:attribute name="android:layout_width">
          <xsl:value-of select="concat(@width,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height=''">
        <xsl:attribute name="android:layout_height">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width=''">
        <xsl:attribute name="android:layout_width">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>

      <xsl:if test="@valign">
        <xsl:choose>
          <xsl:when test="@valign='Bottom'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>bottom</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Center'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>center_vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Stretch'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>fill_vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Top'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>top</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>

      <xsl:if test="@halign">
        <xsl:choose>
          <xsl:when test="@halign='Left'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>left</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Center'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>center_horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Stretch'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>fill_horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Right'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>right</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>

    </xsl:element>
  </xsl:template>

  <xsl:template match="button">
    <xsl:element name="Button">
      <xsl:if test="@name!=''">
        <xsl:attribute name="android:id">
          <xsl:value-of select="concat('@+id/',@name)"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:attribute name="android:text">
        <xsl:value-of select="@text"/>
      </xsl:attribute>
      <xsl:attribute name="android:onClick">
        <xsl:value-of select="@click"/>
      </xsl:attribute>
      <xsl:if test="@height!=''">
        <xsl:attribute name="android:layout_height">
          <xsl:value-of select="concat(@height,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width!=''">
        <xsl:attribute name="android:layout_width">
          <xsl:value-of select="concat(@width,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height=''">
        <xsl:attribute name="android:layout_height">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width=''">
        <xsl:attribute name="android:layout_width">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>

      <xsl:if test="@valign">
        <xsl:choose>
          <xsl:when test="@valign='Bottom'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>bottom</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Center'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>center_vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Stretch'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>fill_vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Top'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>top</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>

      <xsl:if test="@halign">
        <xsl:choose>
          <xsl:when test="@halign='Left'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>left</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Center'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>center_horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Stretch'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>fill_horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Right'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>right</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>

    </xsl:element>
  </xsl:template>

  <xsl:template match="image">

    <xsl:element name="ImageView">
      <xsl:if test="@name!=''">
        <xsl:attribute name="android:id">
          <xsl:value-of select="concat('@+id/',@name)"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height!=''">
        <xsl:attribute name="android:layout_height">
          <xsl:value-of select="concat(@height,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width!=''">
        <xsl:attribute name="android:layout_width">
          <xsl:value-of select="concat(@width,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height=''">
        <xsl:attribute name="android:layout_height">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width=''">
        <xsl:attribute name="android:layout_width">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>

      <xsl:if test="@valign">
        <xsl:choose>
          <xsl:when test="@valign='Bottom'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>bottom</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Center'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>center_vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Stretch'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>fill_vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Top'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>top</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>

      <xsl:if test="@halign">
        <xsl:choose>
          <xsl:when test="@halign='Left'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>left</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Center'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>center_horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Stretch'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>fill_horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Right'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>right</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>

    </xsl:element>

  </xsl:template>

  <xsl:template match="webview">

    <xsl:element name="WebView">
      <xsl:if test="@name!=''">
        <xsl:attribute name="android:id">
          <xsl:value-of select="concat('@+id/',@name)"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height!=''">
        <xsl:attribute name="android:layout_height">
          <xsl:value-of select="concat(@height,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width!=''">
        <xsl:attribute name="android:layout_width">
          <xsl:value-of select="concat(@width,'dp')"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height=''">
        <xsl:attribute name="android:layout_height">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@width=''">
        <xsl:attribute name="android:layout_width">
          <xsl:text>wrap_content</xsl:text>
        </xsl:attribute>
      </xsl:if>

      <xsl:if test="@valign">
        <xsl:choose>
          <xsl:when test="@valign='Bottom'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>bottom</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Center'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>center_vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Stretch'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>fill_vertical</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@valign='Top'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>top</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>

      <xsl:if test="@halign">
        <xsl:choose>
          <xsl:when test="@halign='Left'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>left</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Center'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>center_horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Stretch'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>fill_horizontal</xsl:text>
            </xsl:attribute>
          </xsl:when>
          <xsl:when test="@halign='Right'">
            <xsl:attribute name="android:layout_gravity">
              <xsl:text>right</xsl:text>
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>

    </xsl:element>
  </xsl:template>
  <xsl:template match="class">
  </xsl:template>

</xsl:stylesheet>

UI XSLT (M) - from Windows Phone 8 to Abstract Model

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:a="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

  <xsl:template match="/">
    <xsl:apply-templates select="phone:PhoneApplicationPage"/>
  </xsl:template>
  <xsl:template match="phone:PhoneApplicationPage">
    <xsl:element name="page">
      <xsl:value-of select="phone:PhoneApplicationPage"/>
      <xsl:element name="class">
        <xsl:value-of select="@x:Class"/>
      </xsl:element>
      <xsl:element name="orientation">
        <xsl:attribute name="support">
          <xsl:value-of select="@SupportedOrientations"/>
        </xsl:attribute>
        <xsl:attribute name="orientation">
          <xsl:value-of select="@Orientation"/>
        </xsl:attribute>
      </xsl:element>
      <xsl:element name="systemtray">
        <xsl:attribute name="visible">
          <xsl:value-of select="@shell:SystemTray.IsVisible"/>
        </xsl:attribute>
      </xsl:element>
      <xsl:apply-templates select="node()"/>

    </xsl:element>
  </xsl:template>

  <xsl:template match="a:Grid">
    <xsl:element name="gridlayout">
      <xsl:attribute name="name">
        <xsl:value-of select="@x:Name"/>
      </xsl:attribute>
      <xsl:attribute name="height">
        <xsl:value-of select="@Height"/>
      </xsl:attribute>
      <xsl:attribute name="width">
        <xsl:value-of select="@Width"/>
      </xsl:attribute>
      <xsl:if test="@Grid.Row">
        <xsl:attribute name="row">
          <xsl:value-of select="attribute::Grid.Row"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:attribute name="rows">
        <xsl:choose>
          <xsl:when test="count(a:Grid.RowDefinitions/a:RowDefinition) &gt; 0">
            <xsl:value-of select="count(a:Grid.RowDefinitions/a:RowDefinition)"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="1"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute >

      <xsl:attribute name="columns">
        <xsl:choose>
          <xsl:when test="count(a:Grid.ColumnDefinitions/a:ColumnDefinition) &gt; 0">
            <xsl:value-of select="count(a:Grid.ColumnDefinitions/a:ColumnDefinition)"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="1"/>
          </xsl:otherwise>
        </xsl:choose>

      </xsl:attribute >

      <!--<xsl:element name="tablerow">-->
      <xsl:apply-templates select="node()"/>
      <!--</xsl:element>-->
    </xsl:element>

  </xsl:template>

  <xsl:template match="a:StackPanel">
    <xsl:element name="linearlayout">
      <xsl:attribute name="name">
        <xsl:value-of select="@x:Name"/>
      </xsl:attribute>
      <xsl:attribute name="height">
        <xsl:value-of select="@Height"/>
      </xsl:attribute>
      <xsl:attribute name="width">
        <xsl:value-of select="@Width"/>
      </xsl:attribute>
      <xsl:if test="@Grid.Row">
        <xsl:attribute name="row">
          <xsl:value-of select="attribute::Grid.Row"/>
        </xsl:attribute>
      </xsl:if>

      <xsl:apply-templates select="node()"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="a:TextBlock">
    <xsl:element name="label">
      <xsl:attribute name="name">
        <xsl:value-of select="@x:Name"/>
      </xsl:attribute>
      <xsl:attribute name="text">
        <xsl:value-of select="@Text"/>
      </xsl:attribute>
      <xsl:attribute name="height">
        <xsl:value-of select="@Height"/>
      </xsl:attribute>
      <xsl:attribute name="width">
        <xsl:value-of select="@Width"/>
      </xsl:attribute>
      <xsl:if test="@VerticalAlignment">
        <xsl:attribute name="valign">
          <xsl:value-of select="@VerticalAlignment"/>
        </xsl:attribute>
      </xsl:if>

      <xsl:if test="@HorizontalAlignment">
        <xsl:attribute name="halign">
          <xsl:value-of select="@HorizontalAlignment"/>
        </xsl:attribute>
      </xsl:if>
    </xsl:element>

  </xsl:template>

  <xsl:template match="a:TextBox">
    <xsl:element name="textbox">
      <xsl:attribute name="name">
        <xsl:value-of select="@x:Name"/>
      </xsl:attribute>
      <xsl:attribute name="text">
        <xsl:value-of select="@Text"/>
      </xsl:attribute>
      <xsl:attribute name="height">
        <xsl:value-of select="@Height"/>
      </xsl:attribute>
      <xsl:attribute name="width">
        <xsl:value-of select="@Width"/>
      </xsl:attribute>
      <xsl:if test="@VerticalAlignment">
        <xsl:attribute name="valign">
          <xsl:value-of select="@VerticalAlignment"/>
        </xsl:attribute>
      </xsl:if>

      <xsl:if test="@HorizontalAlignment">
        <xsl:attribute name="halign">
          <xsl:value-of select="@HorizontalAlignment"/>
        </xsl:attribute>
      </xsl:if>
    </xsl:element>

  </xsl:template>

  <xsl:template match="a:Button">
    <xsl:element name="button">
      <xsl:attribute name="name">
        <xsl:value-of select="@Name"/>
      </xsl:attribute>
      <xsl:attribute name="text">
        <xsl:value-of select="@Content"/>
      </xsl:attribute>
      <xsl:attribute name="click">
        <xsl:value-of select="@Click"/>
      </xsl:attribute>
      <xsl:attribute name="height">
        <xsl:value-of select="@Height"/>
      </xsl:attribute>
      <xsl:attribute name="width">
        <xsl:value-of select="@Width"/>
      </xsl:attribute>
      <xsl:if test="@VerticalAlignment">
        <xsl:attribute name="valign">
          <xsl:value-of select="@VerticalAlignment"/>
        </xsl:attribute>
      </xsl:if>

      <xsl:if test="@HorizontalAlignment">
        <xsl:attribute name="halign">
          <xsl:value-of select="@HorizontalAlignment"/>
        </xsl:attribute>
      </xsl:if>
    </xsl:element>
  </xsl:template>

  <xsl:template match="a:Image">

    <xsl:element name="image">
      <xsl:attribute name="name">
        <xsl:value-of select="@Name"/>
      </xsl:attribute>
      <xsl:attribute name="height">
        <xsl:value-of select="@Height"/>
      </xsl:attribute>
      <xsl:attribute name="width">
        <xsl:value-of select="@Width"/>
      </xsl:attribute>


      <xsl:if test="@VerticalAlignment">
        <xsl:attribute name="valign">
          <xsl:value-of select="@VerticalAlignment"/>
        </xsl:attribute>
      </xsl:if>

      <xsl:if test="@HorizontalAlignment">
        <xsl:attribute name="halign">
          <xsl:value-of select="@HorizontalAlignment"/>
        </xsl:attribute>
      </xsl:if>

    </xsl:element>

  </xsl:template>

  <xsl:template match="phone:WebBrowser">

    <xsl:element name="webview">
      <xsl:attribute name="name">
        <xsl:value-of select="@x:Name"/>
      </xsl:attribute>
      <xsl:attribute name="height">

        <xsl:value-of select="@Height"/>
      </xsl:attribute>
      <xsl:attribute name="width">
        <xsl:value-of select="@Width"/>
      </xsl:attribute>
      <xsl:if test="@VerticalAlignment">
        <xsl:attribute name="valign">
          <xsl:value-of select="@VerticalAlignment"/>
        </xsl:attribute>
      </xsl:if>

      <xsl:if test="@HorizontalAlignment">
        <xsl:attribute name="halign">
          <xsl:value-of select="@HorizontalAlignment"/>
        </xsl:attribute>
      </xsl:if>
    </xsl:element>
  </xsl:template>

  <xsl:template match="@a:Grid.Row">
    <xsl:copy>
      <xsl:attribute name="row">
        <xsl:value-of select="."/>
      </xsl:attribute>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>