views:

204

answers:

2

I am not an infopath developer and this is my first real encounter with XSLT. Lately i've had to work on a project where i need to convert an infopath form uploaded to Sharepoint into html. Once in html we can use any thirdparty library to spit out any desired/supported format we want.

What We Do In Code:

  1. We create an XslCompiledTransform object. This is done by parsing the Xsn uploaded to sharepoint and then using the Xsl in there. We use View1.xsl. No issues happen here.
  2. The Xml form is returned as a stream to our conversion method where we create an XmlDocument that the transform needs to be applied to using a stream.
  3. We then pass the XmlDocument to the transform() method along with an XmlTextWriter object which populates an StringWriter object for us. We can then use the StringWriter to give us the html as a string or stream and pass it to the thirdparty library to change to any format like PDF/MHT etc...

The Problem That Occurs After Transformation:

  1. I lose DateFormatting. A date originally setup as 1-12-2009 would become 2009-1-12
  2. I lose Images, Instead of the images we get empty image placeholders with "X" in them.
  3. I lose Master Detail sections.
  4. All html controls come through.I currently convert the htmlstream to a string and have a generic method which filters out any unwanted html. There is also part of my code that filters out selected values in dropdownlists. Doing so i ran into a scenario where there was no "Selected" attribute in the html but a value was selected in thr dropdownlist. THIS WHOLE STRING PARSING IS NOT GRACEFULL, ITS A HACK. Is there a better way to do this?
  5. How can i detect views if there are multiple views in the XSN File.
  6. Is there a simpler way of conversion where passing the xml document would suffice, somthing like XmlForm.CurrentView.Export() method to handle my particular scenario.

Any suggestions, pointer etc would be much appreciated. I am happy to send in the original Xml and the converted Html and the Html left after my method cleans it up.

Thanks in advance.

Muhammad.

A: 

This question is rather large and vague. You will get better responses if you can cut it into smaller chunks: where exactly is what going wrong? If you identify which phase causes which problem, and ask a specific question, you're much more likely to get a response from someone that can help.

Having said that, there are some generic hints that might help get you started:

  1. Your datetime formatting issue is unlikely to be XSL related. XSLT generally doesn't do string formatting very well, so unless someone wrote a rather long and complex XSLT transform as part of your "View1.xsl", XSLT is just spitting out the date the same as it's coming in - so your date problem is probably occuring before the XSLT step.
  2. It sounds like your images are refering to broken links. The output html probably contains <img> tags with src attributes that point to locations that don't exist - find out where these images are supposed to be, and fix the links. This might be as simple as including an appropriate <base> tag in the output html.
Eamon Nerbonne
A: 

This is an interesting idea. But I don't think you will ever get it to work to your satisfaction. The XHTML generated by the xsl transform you are pulling from the xsn is designed to display only in InfoPath. There is quite a lot of InfoPath specific functionality built into the XHTML. You may get something half useful, but you will run into a lot of broken or weird display issues.

For instance, the master-detail functionality is implemented with the xd:linkedToMaster attribute. The xd namespace's URI is http://schemas.microsoft.com/office/infopath/2003.
All references to this namespace (and there are a lot of them) implement InfoPath specific functionality that will not be implemented in any other XHTML renderer.

The only way for you to get this implementation to work would be to implement all the functionality the xd namespace uses in a custom XHTML renderer. Good luck with that.
Sorry I don't have better news.

oillio