p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   enabling controls built in XSLT and imported (http://p2p.wrox.com/showthread.php?t=60123)

charles95621 July 15th, 2007 02:49 PM

enabling controls built in XSLT and imported
 
I have a customer that wants a table of contents built inside a dropdown list box. The problem is that the material for the book is in an XML file, the webform connects the XML with an XSLT file. A profile variable contains the filename of the chapter to be built. There is more than one book so the webform in the builder knows nothing about contents until runtime. All appears to work correctly until time for asp to parse the controls. The controls are coming out as
Code:

<asp:linkbutton name="chapter1Link" runat="server" OnClick="chapter1Link_Click">Chapter1</asp:linkbutton>
 not
Code:

<a id="chapter1lin " href="javascript:__doPostBack('chapter1Link','')">Chapter1</a>
Here is a sample of the simular code

XML
Code:

<?xml version="1.0" encoding="utf-16" ?>
<?xml-stylesheet href="ChapterConverter.xsl" type="text/xsl"?>
<chapter number="6" title="Fashion Week: Presenting the Collections To the Buyers">

  <ChapterIntro>
    <col position="left">
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras lacinia rhoncus
      ante. Ut non neque. Quisque elementum dolor id purus. Nam ultrices enim eget dolor.
      Sed sit amet lectus. Cras leo sapien, tristique sit amet, blandit mollis, tempus sed, metus.
      Sed ut odio in nibh vestibulum congue. Integer rhoncus sapien. Fusce diam dui, dictum ut,
      congue sit amet, egestas quis, erat. Cras massa metus, pellentesque a, vestibulum vel,
      luctus sed, nisi. Proin nulla dolor, egestas ut, interdum nec, ultricies ac, felis. Aliquam
      vel mi sit amet eros venenatis eleifend. Integer facilisis sagittis urna. Nunc vitae metus.
      In placerat, est quis gravida accumsan, tellus lacus imperdiet nulla, non mattis felis pede in ante.
    </col>
    <col position="middle">
      Mauris vestibulum velit et elit. Nam risus nibh, lacinia a, interdum id, sollicitudin sed, nibh. Nunc eget
      enim in leo ultrices lobortis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur
      ridiculus mus. Proin pharetra dui sed enim. Vestibulum ante ipsum primis in faucibus orci luctus
      et ultrices posuere cubilia Curae; Proin accumsan, felis vitae feugiat interdum, est odio lobortis leo,
      non molestie nisl tortor nec leo. Aenean justo. Ut orci metus, feugiat sit amet, dictum ac,
      condimentum nec, massa. Pellentesque eu nunc at augue accumsan rhoncus. Nulla scelerisque.
    </col>
    <col position="right">
      Maecenas a massa. Nulla facilisi. Nam venenatis risus a felis. Pellentesque aliquet felis eget
      tellus. Sed et erat non diam lobortis congue. Etiam et tellus. Proin eget eros sit amet leo
      rhoncus ullamcorper. Aenean ut nulla. Nunc diam. Nam interdum. Curabitur id lorem. Aliquam
      consequat ultrices libero.
    </col>
  </ChapterIntro>
</chapter>

XSLT:
Code:

<!--
  Chapter Converter Translation file
  Purpose: Take Chapter XML File and convert it to XHTML 1.0 Strict
  Author: Charles Russell
  Creation Date:1/10/07

  Notes: In some areas concatenation could be used but for clarity of purpose if statements were used instead
  -->
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
                xmlns:asp="remove">

  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>


  <xsl:template match="chapter">
    <div id="wall">
      <div id="menu">
        <a href="#">Key</a>
        <br />
        <br />
        <select name="Chapter">
          <option value="chapter1">
            <asp:linkbutton name="chapter1Link" runat="server" OnClick="chapter1Link_Click">Chapter1</asp:linkbutton>
          </option>
          <option>
            <asp:linkbutton name="chapter2Link" runat="server" OnClick="chapter2Link_Click">Chapter2</asp:linkbutton>
          </option>
          <option>
            <asp:linkbutton name="chapter3Link" runat="server" OnClick="chapter3Link_Click">Chapter3</asp:linkbutton>
          </option>
          <option>
            <asp:linkbutton name="chapter4Link" runat="server" OnClick="chapter4Link_Click">Chapter4</asp:linkbutton>
          </option>
          <option>
            <asp:linkbutton name="chapter5Link" runat="server" OnClick="chapter5Link_Click">Chapter5</asp:linkbutton>
          </option>
          <option>
            <asp:linkbutton name="chapter6Link" runat="server" OnClick="chapter6Link_Click">Chapter6</asp:linkbutton>
          </option>
        </select>
        <br />
        <br />
        <a href="#">Index/Search</a>
        <br />
      </div>
      <div id="container">
        <div id="internalFrame">
          <div id="chapter_banner">

            Chapter <xsl:value-of select="@number"/>

            <br />
          </div>


          <xsl:apply-templates/>
        </div>
      </div>
    </div>
    <!--</body>
    </html>-->
  </xsl:template>


  <xsl:template match="ChapterIntro">
    <div id="chapter_intro" class="clearfix">

      <div id="col1">

        <xsl:value-of select="./col[@position='left']"  disable-output-escaping="no"/>

      </div>

      <div id="col2">

        <xsl:value-of select="./col[@position='middle']"  disable-output-escaping="no" />

      </div>

      <div id="col3">

        <xsl:value-of select="./col[@position='right']"  disable-output-escaping="no"/>

      </div>

    </div>
  </xsl:template>

</xsl:stylesheet>

aspx
Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="builder.aspx.cs" Inherits="builder" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <link href="style.css" type="text/css" rel ="stylesheet"/>
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>

C#
Code:

using System;
using System.Text;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.Xsl;

public partial class builder : System.Web.UI.Page
{
    private StringWriter ChapterStringBuild = new StringWriter(); //contains Chapter content
    private XslCompiledTransform XslBaseConverter = new XslCompiledTransform();
    private XsltArgumentList Args = new XsltArgumentList();


    protected void Page_Init(object sender, EventArgs e)
    {

        XslBaseConverter.Load(Request.PhysicalApplicationPath + "XSLTFile.xsl");
        XslBaseConverter.Transform(Request.PhysicalApplicationPath + Profile.CurrentFile, Args, ChapterStringBuild);
        string outString = ChapterStringBuild.ToString();
        outString = outString.Replace("xmlns:asp=\"remove\"", "");
        outString = outString.Replace("xmlns=\"\"", "");
        form1.InnerHtml = outString;
        Control ctrl = Page.ParseControl(form1.InnerHtml);

    }


    protected void chapter1Link_Click(object sender, EventArgs e)
    {
        Profile.CurrentFile = "Chap1.xml";
        Response.Redirect("builder.aspx");

    }

    protected void chapter2Link_Click(object sender, EventArgs e)
    {
        Profile.CurrentFile = "Chap2.xml";
        Response.Redirect("builder.aspx");

    }

    protected void chapter3Link_Click(object sender, EventArgs e)
    {
        Profile.CurrentFile = "Chap3.xml";
        Response.Redirect("builder.aspx");

    }

    protected void chapter4Link_Click(object sender, EventArgs e)
    {
        Profile.CurrentFile = "Chap4.xml";
        Response.Redirect("builder.aspx");

    }
    protected void chapter5Link_Click(object sender, EventArgs e)
    {
        Profile.CurrentFile = "Chap5.xml";
        Response.Redirect("builder.aspx");

    }
    protected void chapter6Link_Click(object sender, EventArgs e)
    {
        Profile.CurrentFile = "Chap6.xml";
        Response.Redirect("builder.aspx");

    }

}



All times are GMT -4. The time now is 12:19 PM.

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