XslCompiledTransform 给 Infopath 带来麻烦

发布于 2024-08-05 05:27:09 字数 1037 浏览 8 评论 0原文

我不是 infopath 开发人员,这是我第一次真正接触 XSLT。最近我不得不从事一个项目,我需要将上传到 Sharepoint 的 infopath 表单转换为 html。一旦进入 html,我们就可以使用任何第三方库来输出我们想要的任何所需/支持的格式。

我们在代码中做什么:

  1. 我们创建一个 XslCompiledTransform 对象。这是通过解析上传到共享点的 Xsn 然后使用其中的 Xsl 来完成的。我们使用View1.xsl。这里不会发生任何问题。
  2. Xml 表单作为流返回到我们的转换方法,我们在该方法中创建需要使用流应用转换的 XmlDocument。
  3. 然后,我们将 XmlDocument 与 XmlTextWriter 对象一起传递给 transform() 方法,该对象为我们填充 StringWriter 对象。然后,我们可以使用 StringWriter 将 html 作为字符串或流提供给我们,并将其传递给第三方库以更改为 PDF/MHT 等任何格式...

转换后出现的问题:

  1. 我丢失了 DateFormatting。最初设置为 1-12-2009 的日期将变为 2009-1-12
  2. 我丢失了图像,我们得到的不是图像,而是带有“X”的空图像占位符。
  3. 我丢失了主细节部分。
  4. 所有 html 控件都通过。我目前将 htmlstream 转换为字符串,并有一个通用方法可以过滤掉任何不需要的 html。我的代码中还有一部分会过滤掉下拉列表中的选定值。这样做时,我遇到了这样的情况:html 中没有“Selected”属性,但在下拉列表中选择了一个值。整个字符串解析并不优雅,而是一种黑客行为。有更好的方法吗?
  5. 如果 XSN 文件中有多个视图,我如何检测视图。
  6. 有没有一种更简单的转换方法,传递 xml 文档就足够了,比如 XmlForm.CurrentView.Export() 方法来处理我的特定场景。

任何建议、指示等将不胜感激。我很高兴发送原始 Xml 和转换后的 Html 以及我的方法清理后留下的 Html。

提前致谢。

穆罕默德。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如果没结果 2024-08-12 05:27:09

这个问题比较大,也比较模糊。如果你能把它分成更小的部分,你会得到更好的回应:到底哪里出了问题?如果您确定哪个阶段导致了哪个问题,并提出一个具体问题,您就更有可能得到可以提供帮助的人的答复。

话虽如此,有一些通用提示可能会帮助您入门:

  1. 您的日期时间格式问题不太可能与 XSL 相关。 XSLT 通常不能很好地进行字符串格式化,因此除非有人编写了相当长且复杂的 XSLT 转换作为“View1.xsl”的一部分,否则 XSLT 只是吐出与传入的日期相同的日期 - 所以你的日期问题可能发生在 XSLT 步骤之前。
  2. 听起来您的图像指的是损坏的链接。输出 html 可能包含带有 src 属性的 标记,这些属性指向不存在的位置 - 找出这些图像应该在的位置,并修复链接。这可能就像在输出 html 中包含适当的 标签一样简单。

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.
屋顶上的小猫咪 2024-08-12 05:27:09

这是一个有趣的想法。但我认为你永远不会让它工作得令你满意。您从 xsn 中提取的 xsl 转换生成的 XHTML 设计为仅在 InfoPath 中显示。 XHTML 中内置了很多 InfoPath 特定功能。您可能会得到一些有用的东西,但您会遇到很多损坏或奇怪的显示问题。

例如,主从功能是通过 xd:linkedToMaster 属性实现的。 xd 命名空间的 URI 为 http://schemas.microsoft.com/office/infopath/2003.
对此命名空间的所有引用(其中有很多引用)都实现了 InfoPath 特定的功能,而这些功能不会在任何其他 XHTML 渲染器中实现。

让此实现正常工作的唯一方法是实现 xd 命名空间在自定义 XHTML 渲染器中使用的所有功能。祝你好运。
抱歉我没有更好的消息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文