dynamic xsl ?

bortiquai

Member
Joined
Jul 5, 2007
Messages
17
Programming Experience
Beginner
This may need to go in a new thread, but JohnH has been extremely helpful in getting me going with XML. After playing with it for a while, i seem to be getting it, at least for what I need to do. Thank you for that.

What i would like to know now is if it is possible is to edit XML, and transform it using XSL, all using STRINGS. Meaning, is there a way to do it without having to write the XML/XSL to files first. The xml and xsl code I get is generated programatically (it comes from a web source). So i receive the XML in a string. I need to add my nodes, then transform it and output it to a page.

So it kind of goes something like:

in "Default.aspx":
On a button click: Response.Redirect("DisplayPage.aspx")

in DisplayPage.aspx:

In the Page_Load:
stringXML = api.call.to.get.XML
stringXSL = api.call.to.get.XSL

stringXML = MakeSomeChanges To stringXML

stringHTML = use stringXSL to transform stringXML to HTML

response.write(stringHTML)

Any suggestions on a "best practice" to accomplish this? as you can see, since the "stringHTML" will be different every time "Display_Page.aspx" is loaded, i don't really need to save the XSL/XML to a file, however, that's the only way i've been able to get it to work so far.

Thank you
 
I agree this is a new topic, post moved. You can of course generate xsl, but it really would be best if you didn't have to. The request is also pretty generic, it's hard to tell. Even if content received is different the xml structure normally isn't, also your code that adds probably doesn't change. Or if it adds variance maybe you are doing it the wrong way and it can be done differently to comply with the given structure already there. Pre-written xsl can also be generic to the structure it will transform. It depends on several factors and these could be changed by your design to comply better for ready made code at different stages, instead of generating stylesheets.
 
I think my description of the question was poor.

The XML/XSL is is not "generated" by the program, rather retrieved by the program. The use makes selections, then based upon those selections, the appropriate XML/XSL code is "downloaded" in the form of a string. This code is "relatively" static. I could store it, but would probably rather store it in a database rather than a file. Also, the code can (and does) change periodically, so it would need to be re-downloaded routinely anyway.

Once the code id downloaded, I need to add some data to the XML, again, based upon the users selections.

once I make my changes to the XML, i then use the XSL to transform it to HTML, and post it on the following page.

How I've been doing it is (after user selections):

Download XML and save to a "Temp file"
Download XSL and save to a "temp file"
Edit XML in temp file
transform to html file
Read html file
Response.write(Read.Html.text)

Is there a better way?
Thanks
 
If you're asking if this can be done without storing to files, then yes. The XmlDocument can load from file, url, string or stream. A XslCompiledTransform can be used to write the transformed output directly to the response stream.

You can also use the Xml server control on the page and assign XmlDocument and XslTransform objects to it.
 
Back
Top