我必须用XSLT转换一些XML。XSLT命令如下所示:
<Transformation>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts">
<msxsl:script language="C#" implements-prefix="user">
<msxsl:using namespace="System.IO" />
<![CDATA[
#region Custom-Code
public static string FileExists(string path)
{
FileInfo fi = new FileInfo(path);
return (fi.Exists && (fi.Length >0)).ToString();
}
#endregion
]]>
</msxsl:script>
<xsl:output method="xml" indent="no" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Attachement">
<xsl:choose>
<xsl:when test="@mimetype='XPS'">
<xsl:if test="(@type='MANUAL') and (@print='true') and (user:FileExists(File)='True')">
<xsl:copy-of select="." />
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
</Transformation>如您所见,其中包含了一些C#代码。
现在我的问题是:我正在编写一个Java应用程序。当然,标准的Java类无法处理C#代码。
我从微软找到了这个工具:http://www.microsoft.com/en-us/download/details.aspx?id=21714。
我认为这是可行的,但是您需要MSXML4.0来运行这个实用程序。这不是我自己的问题,但我正在为一家公司开发这个应用程序,如果有一个没有任何依赖关系的工具,那就太好了。另一个问题是,我在某个地方读过,这个实用程序也无法处理这些c#代码,但我不确定它们是否使用了版本1或2。
只需要XSLT1.0转换,但如果可能,我将选择一个支持XSLT2.0的工具
发布于 2014-03-16 09:35:40
如果使用Java,那么就有XSLT1.0 (Xalan,Saxon 6)和XSLT2.0 (Saxon 9)处理器,它们允许您使用Java,例如检查文件是否存在。例如,请参见http://saxon.sourceforge.net/saxon6.5.5/extensibility.html (撒克逊6)或http://xalan.apache.org/xalan-j/extensions.html#java-namespace ( Xalan )或http://www.saxonica.com/documentation/index.html#!extensibility/functions (撒克逊9 )。
我不明白为什么MSXML会有帮助,它是用C/C++完成的COM软件包,不支持调用C#或Java,它有允许使用JScript或VBScript的扩展机制。
https://stackoverflow.com/questions/22428724
复制相似问题