<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/html/body">
      <![CDATA[Seaside program generated by Annick Fron]]>
 <xsl:apply-templates/>
  </xsl:template>
    <!-- don't handle the header as yet -->
    <xsl:template match="/html/head//*">
    </xsl:template>
    <!--Plain text-->
    <xsl:template match="text()" name="text">
        <xsl:if test="string-length(normalize-space(current()))> 0">
        <![CDATA[html text: ']]> <xsl:value-of select="."/><![CDATA['. ]]>
            </xsl:if>
    </xsl:template>
    <!--Paragraph-->
    <xsl:template match="p">
        <![CDATA[html paragraph:[ ]]>
        <xsl:apply-templates/>  
        <![CDATA[]. ]]>
    </xsl:template>  
    <!--Bold-->
    <xsl:template match="b">
        <![CDATA[html bold:[ ]]>
        <xsl:apply-templates/>  
        <![CDATA[]. ]]>
    </xsl:template>  
    <!--Bold-->
    <xsl:template match="i">
        <![CDATA[html italic:[ ]]>
        <xsl:apply-templates/>  
        <![CDATA[]. ]]>
    </xsl:template>  
 <!-- Heading -->     
      <xsl:template match="h1">
          <![CDATA[html heading:[ ]]>
          <xsl:apply-templates/>  
          <![CDATA[]. ]]>
      </xsl:template>  
      <!--Form -->          
    <xsl:template match="form">
        <![CDATA[html form:[ ]]>
        <xsl:apply-templates/>       
        <![CDATA[]. ]]>
    </xsl:template>
      <!-- Table -->
      <xsl:template match="table">
<xsl:call-template name="gatherAttributes"></xsl:call-template>
          <![CDATA[html table:[ ]]>
          <xsl:apply-templates/>       
          <![CDATA[]. ]]>
      </xsl:template>    
      <!-- Table Row-->
      <xsl:template match="tr">
          <xsl:call-template name="gatherAttributes"></xsl:call-template>
          <![CDATA[html tableRow:[ ]]>
          <xsl:apply-templates/>       
          <![CDATA[]. ]]>
      </xsl:template>    
      <!-- Table Data-->
      <xsl:template match="td">
          <xsl:call-template name="gatherAttributes"></xsl:call-template>
          <![CDATA[html tableData:[ ]]>
          <xsl:apply-templates/>       
          <![CDATA[]. ]]>
      </xsl:template>   
    <!-- Input text -->
    <xsl:template match="input[@type='text']">
        <![CDATA[html textInputWithValue: '' callback:[:value| " ]]>
        <!--put the field name as comment-->
        <xsl:value-of select="@name"/>
        <![CDATA[ "]. ]]>
    </xsl:template>   
    <!-- checkbox -->
    <xsl:template match="input[@type='checkbox']">
        <xsl:call-template name="gatherAttributes"></xsl:call-template>
        <![CDATA[html checkboxWithValue: true callback: [:v|].]]>
    </xsl:template>
    <!-- submit button -->
    <xsl:template match="input[@type='submit']">
        <xsl:call-template name="gatherAttributes"></xsl:call-template>
        <![CDATA[html submitButtonWithAction: [] text: ' ]]><xsl:value-of select="@value"/><![CDATA[ '. ]]>
    </xsl:template>
    <!--  Hidden input-->
    <xsl:template match="input[@type='hidden']">
        <xsl:call-template name="gatherAttributes"></xsl:call-template>
        <![CDATA[html hiddenInputWithCallback:[]. ]]>
    </xsl:template>   
    <!-- Radio button -->
    <xsl:template match="input[@type='radio']">
        <xsl:call-template name="gatherAttributes"></xsl:call-template>
        <![CDATA[html radioButtonInGroup: #radioGroupKey selected: true callback: [:v|]. ]]>
    </xsl:template>   
    <!-- Unordered List -->
    <xsl:template match="ul">
        <![CDATA[html unorderedList: [ ]]> 
        <xsl:for-each select="./li">
            <![CDATA[html listItem: [ ]]> 
            <xsl:call-template name="text"/>
            <![CDATA[]. ]]> 
            </xsl:for-each>
            <![CDATA[]. ]]>   
    </xsl:template>
   <!-- Select : don't know what to do with labels and values-->
    <xsl:template match="select">
        <xsl:call-template name="gatherAttributes"></xsl:call-template>
        <![CDATA[html selectFromList: ]]> 
        <xsl:call-template name="gatherLabels"/>
            <![CDATA[ selected: nil  callback: [:v|] labels:[:ea|].]]> 
    </xsl:template>
    
    <!-- Text area -->
    <!--Paragraph-->
    <xsl:template match="textarea">
        <xsl:call-template name="gatherAttributes"></xsl:call-template>
        
        <![CDATA[html textAreaWithValue:' ]]>
        
        <xsl:apply-templates/>  
        <![CDATA[ ' callback: []. ]]>
    </xsl:template>  
    
    <!-- collecting menu values-->
    <xsl:template name="gatherValues">
        <!-- create an array-->
        <![CDATA[#{ ]]> 
        <xsl:for-each select="./option">
            <xsl:value-of select="@value"/> <xsl:text> </xsl:text>
        </xsl:for-each>
        <![CDATA[} ]]> 
    </xsl:template>
    <!-- collecting menu labels-->
    <xsl:template name="gatherLabels">
        <!-- create an array-->
        <![CDATA[#( ]]> 
        <xsl:for-each select="./option">
            <xsl:value-of select="."/> <xsl:text> </xsl:text>
        </xsl:for-each>
        <![CDATA[) ]]> 
    </xsl:template>
    <xsl:template name="gatherAttributes">
        <xsl:for-each select="@*">
            <![CDATA[html attributeAt: ']]><xsl:value-of select="name()"/><![CDATA[' ]]> 
            <![CDATA[ put: ']]><xsl:value-of select="."/><![CDATA['. ]]> 
        </xsl:for-each>

    </xsl:template>
<!-- Images -->
    <xsl:template match="img">
        <xsl:call-template name="gatherAttributes"></xsl:call-template>
        <![CDATA[html  tag: #img.]]>
    </xsl:template>
    <xsl:template match="span">
        <xsl:call-template name="gatherAttributes"></xsl:call-template>
        <![CDATA[html  span:[]]>
        <xsl:apply-templates></xsl:apply-templates>
        <![CDATA[].]]>  
    </xsl:template>
    <xsl:template match="div">
        <xsl:call-template name="gatherAttributes"></xsl:call-template>
        <![CDATA[html  div:[]]>
        <xsl:apply-templates></xsl:apply-templates>
        <![CDATA[].]]>  
    </xsl:template>
</xsl:stylesheet>
