在C#中使用XSLT将RVML转换为SVG [英] Converting RVML to SVG using XSLT in C#

查看:195
本文介绍了在C#中使用XSLT将RVML转换为SVG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#Web应用程序,它使用 RaphaelJS 生成SVG代码,然后我需要将其转换为PNG用户之间的一般互操作性(请参阅此处的上一个问题

I have a C# web application which generates SVG code using RaphaelJS, which I then need to convert to PNG for general interoperability amongst users (please see my previous question here also)

问题在于,而不是似乎是标准的SVG代码,Internet Explorer会产生RVML代码。我的解决方案在Firefox和其他浏览器中成功运行,使用 Inkscape的命令行实用程序来转换普通的SVG文件到PNG。但是Inkscape不会从RVML转换。

The problem is that, rather than SVG code which seems to be the norm, Internet Explorer churns out RVML code. My solution works successfully in Firefox and other browsers by using Inkscape's command line utility to convert the plain SVG file to PNG. But Inkscape won't convert from RVML.

因此,除了重写我的应用程序以避免RahaelJs之外,下一个合乎逻辑的事情是在运行之前将RVML转换为SVG它通过Inkscape。为此,我找到了这篇文章,并使用了代码示例靠近页面顶部。我用来转换RVML文件的XSL文件是 VectorConverter 使用的文件,你可以使用它下载并查看。

So the next logical thing to do, apart from rewrite my application to avoid RahaelJs, is to convert the RVML to SVG before running it through Inkscape. To do this I've found this article, and have used the code example near the top of the page. The XSL file I've used to convert the RVML file is the one used by VectorConverter which you can download and look at.

我应该提到没有运行时错误 - 所有文件都输出正确的位置,即来自服务器端XSLT转换的XML - > SVG,以及SVG - >来自Inkscape转换的PNG。

I should mention there are no runtime errors - all the files output in the right place, i.e. the XML -> SVG from the server-side XSLT conversion, and the SVG -> PNG from the Inkscape conversion.

总结一下这种情况,浏览Firefox时很好 - 浏览Internet Explorer时,XML-> SVG转换生成的SVG文件会输出一个有效的SVG文件但SVG标签内没有实际内容。 我的问题是,是否有其他人在执行此任务方面取得了任何成功,或者是否有人对我做错了什么有任何建议?

To summarize the situation, when browsing through Firefox - it's fine - when browsing through Internet explorer, the SVG file generated by the XML->SVG conversion outputs a valid SVG file but with no actual content inside the SVG tags. My question is whether anyone else has had any success in doing this task, or if anyone has any suggestions on what I'm doing wrong?

谢谢

推荐答案

是的,我们在其中一个项目上完成了同样的事情。问题是RapahelJS生成的VML应该稍微改变一下,以适应VectorConverter方案(顺便说一下,我们使用了该工具第二版中包含的方案)。以下是我们在实际转换之前所做的更改:

Yes, we did exactly the same thing on one of our projects. The problem is that the VML generated by RapahelJS should be altered a little bit in order to fit to the VectorConverter scheme (btw, we used scheme included in the 2nd version of this tool). Here are the changes we were making before actual transform:

string clearedVml = new Regex("<rvml.*/rvml:group>")
    .Match(rafaelOutputVml)
    .Value
    .Replace("rvml:", "v:")
    .Replace("class=rvml", "")
    .Replace("filterMatrix", "");

转换后的结果应插入以下标记中:

After that transformation result should be inserted in the following markup:

        private const string vmlFormat = 
@"
<?xml version=""1.0""?>
<HTML xmlns:v = ""urn:schemas-microsoft-com:vml"" xmlns=""http://www.w3.org/1999/xhtml"">

<HEAD>
<STYLE>v\:* {{
    BEHAVIOR: url(#VMLRender)
}}
</STYLE>
</HEAD>
<BODY>
{0}
</BODY>
</HTML>
";
...
var sReader = new StringReader( String.Format( vmlFormat ,clearedVml ).Trim() );

现在只能执行到SVG的实际转换。

and only now the actual transform to SVG should be performed.

希望有所帮助

这篇关于在C#中使用XSLT将RVML转换为SVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆