Embedding XML into ASPX question

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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
    Victor Fees Guest

  2. Similar Questions and Discussions

    1. passing a token from pageA.aspx to pageB.aspx
      I am trying to get pageA.aspx gridView to pass a key (say deptID) to pageB.aspx which will use the value passed as a filter in it's own griView...
    2. Image Question (embedding and url)
      Hi, I'm evaluating flex, like it so far, but disapointed by what I think are some serious limitations in the mx:Image control. I need to...
    3. Font Embedding Question
      I have created a document in Quark Xpress 6.5. I then created a pdf file of the document using custom distiller settings. Under the "Fonts" tab in...
    4. aspx, word question
      Hi 2 all, I have a question and hope that some of you might been able to give me a hint or something. I am bulding a web application where i...
    5. Aspx pages and webcontrols question
      Hi, i have a newbie dud I would like to develop a portal, and i have two web controls (the left menu, and the top menu The only thing that i...
  3. #2

    Default 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
    [url]http://www.takempis.com[/url]
    Complex things are made up of
    lots of simple things.

    "Victor Fees" <vfees_spamless@seventhfloorinc.com> wrote in message
    news:Xns93C84EAA2A102vfeesseventhfloorinc@207.46.2 48.16...
    > 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 Guest

  4. #3

    Default Re: Embedding XML into ASPX question

    Oleg Tkachenko <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in
    news:u9cpYOqVDHA.1704@TK2MSFTNGP11.phx.gbl:


    a little tricky . . . but it worked. Thanks.
    Victor Fees Guest

  5. #4

    Default Re: Embedding XML into ASPX question

    Victor Fees wrote:
    > 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.
    You can put placeholder <div> between them and fill transformation result to
    its InnerHtml property.
    --
    Oleg Tkachenko
    [url]http://www.tkachenko.com/blog[/url]
    Multiconn Technologies, Israel

    Oleg Tkachenko Guest

  6. #5

    Default Re: Embedding XML into ASPX question

    Vic,

    The System.Web.UI.WebControls.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.Control.

    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.Xpath;
    using System.Xml.Xsl;

    public class MyXmlTransformer : System.Web.UI.Control
    {
    protected override void Render(HtmlTextWriter writer)
    {
    XPathDocument theXDoc = new XPathDocument("myxml.xml");

    XslTransform theXslt = new XslTransform();
    theXslt.Load("thexslt.xsl");

    theXslt.Transform(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@seventhfloorinc.com>
    Newsgroups:
    microsoft.public.dotnet.general,microsoft.public.d otnet.framework.aspnet,mic
    rosoft.public.dotnet.xml
    Sent: Wednesday, July 30, 2003 2:44 PM
    Subject: 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
    "Victor Fees" <vfees_spamless@seventhfloorinc.com> wrote in message
    news:Xns93C84EAA2A102vfeesseventhfloorinc@207.46.2 48.16...
    > 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

    Dave Keenan Guest

  7. #6

    Default Re: Embedding XML into ASPX question

    Oleg Tkachenko <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in
    news:u9cpYOqVDHA.1704@TK2MSFTNGP11.phx.gbl:
    > Victor Fees wrote:
    >
    >> 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.
    > You can put placeholder <div> between them and fill transformation
    > result to its InnerHtml property.
    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.GetType().ToString()
    + "<br>"
    Else
    Me.Label1.Text += "Control.ID = " + objControl.ID.ToString +
    "<br>"
    End If
    If objControl.HasControls Then
    Me.Label1.Text += "this control has children<br>"
    Dim objChild As Control
    For Each objChild In objControl.Controls
    Me.DrillDown(objChild)
    Next
    End If
    End Sub

    In my XSLT, I'm doing this:

    <xsl:for-each select="Survey/Questions/Question">
    <p><xsl:value-of select="QuestionText">
    </xsl:value-of>
    <xsl:choose>
    <xsl:when test="@type = 'inputbox'">
    <input>
    <xsl:attribute name="type">text
    </xsl:attribute>
    <xsl:attribute name="id">txtQ
    <xsl:value-of select="@id"></xsl:value-of></xsl:attribute>
    <xsl:attribute name="name">txtQ
    <xsl:value-of select="@id"></xsl:value-of></xsl:attribute>
    <xsl:attribute 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?
    Victor Fees Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139