XSL 转换器






1.86/5 (6投票s)
一个简单的 XSL 转换编辑器。
引言
这个编辑器可以帮助测试 XSL 转换。 如果您正在为 Web 项目开发 XSLT,并且希望在发布到 Web 服务器之前进行测试,它将非常有用。 您还可以使用此编辑器检查 XSLT 语法错误和转换结果。
背景
在最近的任务中,我有机会使用 XSLT。 在开发 XSLT 文件时,我发现 MSXML.dll 不支持当前 XSLT/XPath 版本中的所有函数。 因此,我制作了这个小工具来测试 XSLT 输出和语法错误。
Using the Code
Dim sResult As New System.IO.StringWriter
'loan XML
xmlDoc.LoadXml(rtxtXML.Text)
'load XSL
xslDoc.LoadXml(rtxtXSL.Text)
Dim xslTransform As New System.Xml.Xsl.XslTransform
'if xsl has any import statements create Evidence For the Url
Dim evidence As System.Security.Policy.Evidence = _
XmlSecureResolver.CreateEvidenceForUrl("https:///")
evidence.AddAssembly(Me.GetType().Assembly)
xslTransform.Load(xslDoc, New Xml.XmlUrlResolver, evidence)
xslTransform.Transform(xmlDoc, Nothing, sResult, Nothing)
rtxtResult.Text = sResult.GetStringBuilder().ToString()
'select result tab
tbctlMain.SelectedIndex = 2
Trace("Transformation compleated....")
如何使用
- 将 XML 数据复制到 XML 选项卡中,或从“文件”菜单打开现有的 XML 文件。
- 将 XSL 脚本复制到 XSL 选项卡中,或从“文件”菜单打开现有的 XSL 文件。
- 单击“转换”菜单项以测试转换。 如果 XSLT 没问题,您应该在“结果”选项卡中看到输出。
示例 XML
<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
示例 XSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <root> <xsl:apply-templates/> </root> </xsl:template> <xsl:template match="bookstore"> <!-- Prices and books --> <bookstore> <xsl:apply-templates select="book"/> </bookstore> </xsl:template> <xsl:template match="book"> <book> <xsl:attribute name="ISBN"> <xsl:value-of select="@ISBN"/> </xsl:attribute> <price><xsl:value-of select="price"/></price><xsl:text> </xsl:text> </book> </xsl:template> </xsl:stylesheet>
历史
- 创建于 2007年4月17日。