Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 2nd, 2005, 04:14 AM
Registered User
 
Join Date: Aug 2005
Location: bangalore, karnataka, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to shashi1312
Default Dynamic generation of asp.net server controls

hai
    i have a problem prolonging for days from now
    i have an xml document which describes all the fields that has to be used dynamically populated on to page after a criteria I WILL GIVE MY XML AND XSLT AND TRANSFORM METHODS can anybody go through this and help

XML DOC
        <FIELDS>

                <FIELD type="TextBox" label="Last Name:" required="true" runat="server">
                    <PROPERTIES>
                        <PROPERTY name="ID">LAST_NAME</PROPERTY>
                    </PROPERTIES>
                </FIELD>

                <FIELD type="TextBox" label="Description:" required="true" runat="server">
                    <PROPERTIES>
                        <PROPERTY name="ID">DESCRIPTION</PROPERTY>
                        <PROPERTY name="TextMode">MultiLine</PROPERTY>
                        <PROPERTY name="Cols">30</PROPERTY>
                        <PROPERTY name="Rows">2</PROPERTY>
                    </PROPERTIES>
                </FIELD>

                <FIELD type="TextBox" label="Prefilled Contrl:" required="true">
                    <PROPERTIES>
                        <PROPERTY name="ID">PREFILLED_CONTROL</PROPERTY>
                        <PROPERTY name="Text">Some Text</PROPERTY>
                    </PROPERTIES>
                </FIELD>
                <!-- regular text box which must filled
                                 and allowed Date datata type -->
                <FIELD type="TextBox" label="Start Date:" required="true" validation="Date">
                    <PROPERTIES>
                        <PROPERTY name="ID">START_DATE</PROPERTY>
                    </PROPERTIES>
                </FIELD>

                <FIELD type="DropDownList" label="Title:" required="true">
                    <PROPERTIES>
                        <PROPERTY name="ID">TITLE</PROPERTY>
                    </PROPERTIES>
                    <LISTITEMS>
                        <LISTITEM value="">Select One</LISTITEM>
                        <LISTITEM value="1">Architector</LISTITEM>
                        <LISTITEM value="2">Sr. Developer</LISTITEM>
                        <LISTITEM value="3">Programmer</LISTITEM>
                        <LISTITEM value="4">Web Designer</LISTITEM>
                    </LISTITEMS>
                </FIELD>

                <FIELD type="RadioButtonList" label="Are you US citizen?" required="true">
                    <PROPERTIES>
                        <PROPERTY name="ID">IS_US_CITIZEN</PROPERTY>
                        <PROPERTY name="RepeatColumns">1</PROPERTY>
                        <PROPERTY name="RepeatDirection">Vertical</PROPERTY>
                        <PROPERTY name="RepeatLayout">Table</PROPERTY>
                        <PROPERTY name="TextAlign">Right</PROPERTY>
                    </PROPERTIES>
                    <LISTITEMS>
                        <LISTITEM value="1">Yes</LISTITEM>
                        <LISTITEM value="0">No</LISTITEM>
                    </LISTITEMS>
                </FIELD>

                <FIELD type="CheckBoxList" label="Languages:" required="true">
                    <PROPERTIES>
                        <PROPERTY name="ID">LANGUAGES</PROPERTY>
                        <PROPERTY name="RepeatColumns">1</PROPERTY>
                        <PROPERTY name="RepeatDirection">Vertical</PROPERTY>
                        <PROPERTY name="RepeatLayout">Table</PROPERTY>
                        <PROPERTY name="TextAlign">Right</PROPERTY>
                    </PROPERTIES>
                    <LISTITEMS>
                        <LISTITEM value="C#">C#</LISTITEM>
                        <LISTITEM value="Java">Java</LISTITEM>
                        <LISTITEM value="VB">Visual Basic</LISTITEM>
                    </LISTITEMS>
                </FIELD>

                <FIELD type="HyperLink" label="">
                    <PROPERTIES>
                        <PROPERTY name="ID">LINK</PROPERTY>
                        <PROPERTY name="NavigateUrl">javascript:void(alert('Hello ooo'));</PROPERTY>
                        <PROPERTY name="Text">Say Hello</PROPERTY>
                    </PROPERTIES>
                </FIELD>
            </FIELDS>

XSL DOC

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="remove">
  <xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes">
  </xsl:output>
  <xsl:template match="/">
  <HTML>
   <BODY>
    <table cellpadding="0" cellspacing="5">
      <tr>
       <td>


       <xsl:for-each select="FIELDS/FIELD">


       <xsl:element name="tr">
        <xsl:attribute name="id">
          <xsl:value-of select="PROPERTIES/PROPERTY[@name='ID']"></xsl:value-of>

        </xsl:attribute>


        <xsl:if test="@display='none'">
         <xsl:attribute name="style">display:none;</xsl:attribute>
        </xsl:if>

        <xsl:choose>


         <xsl:when test="@type='HTML'">
          <td colspan="3">

          </td>
         </xsl:when>


         <xsl:otherwise>


         <td valign="top">
          <xsl:value-of select="@label" />
         </td>


         <td>


          <xsl:element name="asp:{@type}">
           <xsl:attribute name="runat">server</xsl:attribute>
           <xsl:for-each select="./PROPERTIES/PROPERTY">
             <xsl:attribute name="{@name}">
               <xsl:value-of select="current()"></xsl:value-of>
             </xsl:attribute>
           </xsl:for-each>
           <xsl:for-each select="./LISTITEMS/LISTITEM">
            <asp:ListItem value="{@value}">
              <xsl:value-of select="current()"></xsl:value-of>
            </asp:ListItem>
           </xsl:for-each>
          </xsl:element>
         </td>


         <td>
          <xsl:if test="@required='true'">
           <asp:RequiredFieldValidator ErrorMessage="Required" runat="server"
                 ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
          </xsl:if>

          <xsl:if test="@validation='Date'">
           <asp:CompareValidator ErrorMessage="Dates Only" runat="server"
                Operator="DataTypeCheck" Type="Date"
                ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
          </xsl:if>

          <xsl:if test="@validation='Number'">
           <asp:CompareValidator ErrorMessage="Numbers Only" runat="server"
               Operator="DataTypeCheck" Type="Integer"
               ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
          </xsl:if>

          <xsl:if test="@validation='Currency'">
           <asp:CompareValidator ErrorMessage="Currency Only" runat="server"
               Operator="DataTypeCheck" Type="Currency"
               ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
          </xsl:if>
         </td>
        </xsl:otherwise>

       </xsl:choose>
      </xsl:element>

      </xsl:for-each>
      </td>
      </tr>
     </table>


     </BODY>
     </HTML>
  </xsl:template>
</xsl:stylesheet>

transform function

private void CreateSurvey()
        {
            // Load the data source
            //WebForm1 form=new WebForm1 ();
            XmlDocument xml = new XmlDocument();
            XslTransform xslt = new XslTransform();
            string xmlpath=Server.MapPath("XMLFile.xml");

            xml.Load(Server.MapPath("XMLFile.xml"));
            xslt.Load(Server.MapPath("XSLTFile1.xslt"));
            XPathDocument doc=new XPathDocument(xmlpath);

            StringWriter sw = new StringWriter();

            xslt.Transform(doc, null, sw);

            string result = sw.ToString();

            result = result.Replace("xmlns:asp=\"remove\"","");

            Control ctrl = Page.ParseControl(result);
            this.Controls.Add(ctrl);



        }


shashi
  #2 (permalink)  
Old August 2nd, 2005, 04:52 AM
Registered User
 
Join Date: Aug 2005
Location: bangalore, karnataka, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to shashi1312
Default

actually i need to populate a asp.net page with xml and xslt please any one can help me?

shashi


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Dynamic ASP.NET Server Controls Using XML kwilliams XSLT 0 October 6th, 2006 01:42 PM
Dynamic generation of .Net button in a position sonaldewle General .NET 0 April 3rd, 2006 03:51 AM
Dynamic ASP button generation Lloyd_Christmas Classic ASP Basics 1 May 17th, 2005 06:50 PM
Dynamic generation of controls in ASP.NET Maxood ASP.NET 1.0 and 1.1 Basics 2 March 8th, 2004 07:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.