Embedding XML into ASPX question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Victor Fees

    #1

    Embedding XML into ASPX question

    I have an XML string in a database that I would like to display using XSLT.
    All of that works like a champ, but I can't figure out how to embed the XML
    inside an ASPX page.

    For example, I have an ASPX page with a Header User Control and a Footer
    User Control. I'd like to put the transformed XML right in the middle. It
    seems like this is something that should be doable, but I can't quite
    figure it out. Is anyone out there doing this, and if so, can you point me
    in the right direction?

    Thanks,
    Vic Fees
  • Kevin Spencer

    #2
    Re: Embedding XML into ASPX question

    Put a PlaceHolder or LiteralControl where you want the XML to be, and add it
    to that control.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

    Complex things are made up of
    lots of simple things.

    "Victor Fees" <vfees_spamless @seventhfloorin c.com> wrote in message
    news:Xns93C84EA A2A102vfeesseve nthfloorinc@207 .46.248.16...[color=blue]
    > I have an XML string in a database that I would like to display using[/color]
    XSLT.[color=blue]
    > All of that works like a champ, but I can't figure out how to embed the[/color]
    XML[color=blue]
    > inside an ASPX page.
    >
    > For example, I have an ASPX page with a Header User Control and a Footer
    > User Control. I'd like to put the transformed XML right in the middle.[/color]
    It[color=blue]
    > seems like this is something that should be doable, but I can't quite
    > figure it out. Is anyone out there doing this, and if so, can you point[/color]
    me[color=blue]
    > in the right direction?
    >
    > Thanks,
    > Vic Fees[/color]


    Comment

    • Oleg Tkachenko

      #3
      Re: Embedding XML into ASPX question

      Victor Fees wrote:
      [color=blue]
      > I have an XML string in a database that I would like to display using XSLT.
      > All of that works like a champ, but I can't figure out how to embed the XML
      > inside an ASPX page.
      >
      > For example, I have an ASPX page with a Header User Control and a Footer
      > User Control. I'd like to put the transformed XML right in the middle.[/color]
      You can put placeholder <div> between them and fill transformation result to
      its InnerHtml property.
      --
      Oleg Tkachenko

      Multiconn Technologies, Israel

      Comment

      • Victor Fees

        #4
        Re: Embedding XML into ASPX question

        Oleg Tkachenko <oleg@NO_SPAM_P LEASEtkachenko. com> wrote in
        news:u9cpYOqVDH A.1704@TK2MSFTN GP11.phx.gbl:


        a little tricky . . . but it worked. Thanks.

        Comment

        • Dave Keenan

          #5
          Re: Embedding XML into ASPX question

          Vic,

          The System.Web.UI.W ebControls.Xml class is designed for exactly this
          functionality.
          It has 2 pulic properties: Document and Transform which take your Xml
          Document and Xslt Transform Document respectively and
          perform the transform for you. Like any WebControl it can just be dropped
          on your aspx page.

          Another way to do it, and the way I do it for performance reasons, is to
          write your own Custom Control derived from System.Web.UI.C ontrol.

          This gives you an HtmlTextWriter that you can write to by performing an Xsl
          Transform on an XPath Document, the XPath document is more
          performant than the Xml Document class. Try something like the following:

          using System;
          using System.Web;
          using System.Web.UI;
          using System.Xml;
          using System.Xml.Xpat h;
          using System.Xml.Xsl;

          public class MyXmlTransforme r : System.Web.UI.C ontrol
          {
          protected override void Render(HtmlText Writer writer)
          {
          XPathDocument theXDoc = new XPathDocument(" myxml.xml");

          XslTransform theXslt = new XslTransform();
          theXslt.Load("t hexslt.xsl");

          theXslt.Transfo rm(theXDoc, null, writer);
          }
          }

          Then just drop one of these on your aspx page. Obviously the above can be
          made more re-usable by exposing the
          XPathDocument and XslTransform as properties of the class, mess about with
          it and see what you come up with.

          Hope this helps,

          Dave


          ----- Original Message -----
          From: "Victor Fees" <vfees_spamless @seventhfloorin c.com>
          Newsgroups:
          microsoft.publi c.dotnet.genera l,microsoft.pub lic.dotnet.fram ework.aspnet,mi c
          rosoft.public.d otnet.xml
          Sent: Wednesday, July 30, 2003 2:44 PM
          Subject: Embedding XML into ASPX question

          [color=blue]
          > I have an XML string in a database that I would like to display using[/color]
          XSLT.[color=blue]
          > All of that works like a champ, but I can't figure out how to embed the[/color]
          XML[color=blue]
          > inside an ASPX page.
          >
          > For example, I have an ASPX page with a Header User Control and a Footer
          > User Control. I'd like to put the transformed XML right in the middle.[/color]
          It[color=blue]
          > seems like this is something that should be doable, but I can't quite
          > figure it out. Is anyone out there doing this, and if so, can you point[/color]
          me[color=blue]
          > in the right direction?
          >
          > Thanks,
          > Vic Fees[/color]
          "Victor Fees" <vfees_spamless @seventhfloorin c.com> wrote in message
          news:Xns93C84EA A2A102vfeesseve nthfloorinc@207 .46.248.16...[color=blue]
          > I have an XML string in a database that I would like to display using[/color]
          XSLT.[color=blue]
          > All of that works like a champ, but I can't figure out how to embed the[/color]
          XML[color=blue]
          > inside an ASPX page.
          >
          > For example, I have an ASPX page with a Header User Control and a Footer
          > User Control. I'd like to put the transformed XML right in the middle.[/color]
          It[color=blue]
          > seems like this is something that should be doable, but I can't quite
          > figure it out. Is anyone out there doing this, and if so, can you point[/color]
          me[color=blue]
          > in the right direction?
          >
          > Thanks,
          > Vic Fees[/color]


          Comment

          • Victor Fees

            #6
            Re: Embedding XML into ASPX question

            Oleg Tkachenko <oleg@NO_SPAM_P LEASEtkachenko. com> wrote in
            news:u9cpYOqVDH A.1704@TK2MSFTN GP11.phx.gbl:
            [color=blue]
            > Victor Fees wrote:
            >[color=green]
            >> I have an XML string in a database that I would like to display using
            >> XSLT. All of that works like a champ, but I can't figure out how to
            >> embed the XML inside an ASPX page.
            >>
            >> For example, I have an ASPX page with a Header User Control and a
            >> Footer User Control. I'd like to put the transformed XML right in
            >> the middle.[/color]
            > You can put placeholder <div> between them and fill transformation
            > result to its InnerHtml property.[/color]

            I have a follow-up question about this . . . . I have HTML generic
            textboxes in my XSLT, and would like to reference them in the code-behind
            for the page in which I am embedding the XML. I've used a recursive
            subroutine to prove that I can see the control in the code-behind, but I
            can't seem to access anything of value (i.e., ID).

            Private Sub DrillDown(ByVal objControl As Control)
            If objControl.ID Is Nothing Then
            Me.Label1.Text += "Type: " + objControl.GetT ype().ToString( )
            + "<br>"
            Else
            Me.Label1.Text += "Control.ID = " + objControl.ID.T oString +
            "<br>"
            End If
            If objControl.HasC ontrols Then
            Me.Label1.Text += "this control has children<br>"
            Dim objChild As Control
            For Each objChild In objControl.Cont rols
            Me.DrillDown(ob jChild)
            Next
            End If
            End Sub

            In my XSLT, I'm doing this:

            <xsl:for-each select="Survey/Questions/Question">
            <p><xsl:value-of select="Questio nText">
            </xsl:value-of>
            <xsl:choose>
            <xsl:when test="@type = 'inputbox'">
            <input>
            <xsl:attribut e name="type">tex t
            </xsl:attribute>
            <xsl:attribut e name="id">txtQ
            <xsl:value-of select="@id"></xsl:value-of></xsl:attribute>
            <xsl:attribut e name="name">txt Q
            <xsl:value-of select="@id"></xsl:value-of></xsl:attribute>
            <xsl:attribut e name="runat">
            server</xsl:attribute>
            </input>
            </xsl:when>
            </xsl:choose>
            <xsl:value-of select="@id"></xsl:value-of>
            </p>
            </xsl:for-each>

            So, you can see that the "inputbox" is a generic html <input> with an id
            of txtQ1 and a name of txtQ1. However, I can't find a variable that
            gives me this value in the code behind. I've tried using <asp:TextBox>
            embedded in my XML, but that provides a new set of problems -- the ID
            turns out to be TextBox1, and the display gets worse.

            Regardless, any idea what I'm doing wrong here?

            Comment

            Working...