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

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>

ليست هناك تعليقات:

إرسال تعليق