使用经典的 ASP 和 MSXML2.DOMDocument,我试图将此 XML 转换为 HTML 表格。谁能指出我正确的方向?什么是逻辑过程?
这是我要转换的 XML。
所需的输出格式在这里 - http://ashleylangford.com/tableex.gif
<?xml version="1.0"?>
<inv-balance>
<item color-code="50" description="G200 ASH.GREY S" item-number="0620404A3" price="$2.60" size-code="3" special-expiry="06/30/12" specialPrice="$1.92" style-code="G200">
<transit-time days="0">386</transit-time>
<transit-time days="1">6602</transit-time>
<transit-time days="2">9090</transit-time>
<transit-time days="3">88755</transit-time>
<transit-time days="5">2394</transit-time>
<transit-time days="All">107227</transit-time>
</item>
<item color-code="50" description="G200 ASH.GREY M" item-number="0620404A4" price="$2.60" size-code="4" special-expiry="06/30/12" specialPrice="$1.92" style-code="G200">
<transit-time days="0">422</transit-time>
<transit-time days="1">9428</transit-time>
<transit-time days="2">12162</transit-time>
<transit-time days="3">86798</transit-time>
<transit-time days="5">3523</transit-time>
<transit-time days="All">112333</transit-time>
</item>
<item color-code="50" description="G200 ASH.GREY L" item-number="0620404A5" price="$2.60" size-code="5" special-expiry="06/30/12" specialPrice="$1.92" style-code="G200">
<transit-time days="0">548</transit-time>
<transit-time days="1">14810</transit-time>
<transit-time days="2">17335</transit-time>
<transit-time days="3">84832</transit-time>
<transit-time days="5">5611</transit-time>
<transit-time days="All">123136</transit-time>
</item>
<item color-code="50" description="G200 ASH.GREY XL" item-number="0620404A6" price="$2.60" size-code="6" special-expiry="06/30/12" specialPrice="$1.92" style-code="G200">
<transit-time days="0">644</transit-time>
<transit-time days="1">15040</transit-time>
<transit-time days="2">16954</transit-time>
<transit-time days="3">50635</transit-time>
<transit-time days="5">5995</transit-time>
<transit-time days="All">89268</transit-time>
</item>
<item color-code="50" description="G200 ASH.GREY 2XL" item-number="0620404A7" price="$4.19" size-code="7" special-expiry="06/30/12" specialPrice="$3.39" style-code="G200">
<transit-time days="0">343</transit-time>
<transit-time days="1">5374</transit-time>
<transit-time days="2">7016</transit-time>
<transit-time days="3">26033</transit-time>
<transit-time days="5">2592</transit-time>
<transit-time days="All">41358</transit-time>
</item>
<item color-code="50" description="G200 ASH.GREY 3XL" item-number="0620404A8" price="$4.33" size-code="8" special-expiry="06/30/12" specialPrice="$3.39" style-code="G200">
<transit-time days="0">153</transit-time>
<transit-time days="1">1242</transit-time>
<transit-time days="2">1896</transit-time>
<transit-time days="3">4699</transit-time>
<transit-time days="5">803</transit-time>
<transit-time days="All">8793</transit-time>
</item>
<item color-code="50" description="G200 ASH.GREY 4XL" item-number="0620404A9" price="$4.49" size-code="9" special-expiry="06/30/12" specialPrice="$3.39" style-code="G200">
<transit-time days="0">18</transit-time>
<transit-time days="1">78</transit-time>
<transit-time days="2">159</transit-time>
<transit-time days="3">237</transit-time>
<transit-time days="5">62</transit-time>
<transit-time days="All">554</transit-time>
</item>
<item color-code="50" description="G200 ASH.GREY 5XL" item-number="0620404AA" price="$4.63" size-code="0" special-expiry="06/30/12" specialPrice="$3.39" style-code="G200">
<transit-time days="0">16</transit-time>
<transit-time days="1">295</transit-time>
<transit-time days="2">215</transit-time>
<transit-time days="3">2127</transit-time>
<transit-time days="5">119</transit-time>
<transit-time days="All">2772</transit-time>
</item>
</inv-balance>
最佳答案
这是让你关闭的代码块
您需要的 ASP 页面:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Option Explicit
Dim dom : Set dom = CreateObject("MSXML2.DOMDocument.3.0")
dom.async = false
dom.load Server.MapPath("/inventory/stockfor0620404A.xml")
Dim xslTemplate
If IsObject(Application("stocktablerendering")) Then
Set xslTemplate = Application("stocktablerendering")
Else
Dim xsl : Set xsl = CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
xsl.async = false
xsl.load Server.MapPath("/xslstylesheets/stocktablerendering.xsl")
Set xslTemplate = CreateObject("MSXML2.XSLTemplate.3.0")
xslTemplate.stylesheet = xsl
Set Application("stocktablerendering") = xslTemplate
End If
Dim xslProc: Set xslProc = xslTemplate.createProcessor()
xslProc.input = dom
xslProc.transform()
Response.CharSet = "UTF-8"
Response.Write xslProc.output
%>
此代码假定您的 XML 位于“/inventory/stockfor0620404A.xml”的文件中,并且以下 XSL 位于“/xslstylesheets/stocktablerendering.xsl”的文件中:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="transitTimes" match="transit-time" use="@days" />
<xsl:output method="html" />
<xsl:template match="/inv-balance">
<html>
<body>
<table>
<thead>
<tr>
<th> </th>
<th>S</th>
<th>M</th>
<th>L</th>
<th>XL</th>
<th>2XL</th>
<th>3XL</th>
<th>4XL</th>
<th>5XL</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="item/transit-time[count(key('transitTimes', @days)[1] | .) = 1]">
<xsl:sort select="@days" />
</xsl:apply-templates>
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="transit-time">
<xsl:variable name="days" select="@days" />
<tr>
<td>
Stock available to reach you in <xsl:value-of select="@days" /> day
</td>
<xsl:for-each select="../../item/transit-time[@days=$days]">
<td>
<span>
<xsl:value-of select="." />
</span>
</td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
此代码中有大量假设,但从您的问题中的 XML 中提供了一个与您的问题所在的表格格式相似的表格。
关于html - XML 数据到 HTML - 看起来很容易,但我很难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9333003/
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
我正在使用Rails构建一个简单的聊天应用程序。当用户输入url时,我希望将其输出为html链接(即“url”)。我想知道在Ruby中是否有任何库或众所周知的方法可以做到这一点。如果没有,我有一些不错的正则表达式示例代码可以使用... 最佳答案 查看auto_linkRails提供的辅助方法。这会将所有URL和电子邮件地址变成可点击的链接(htmlanchor标记)。这是文档中的代码示例。auto_link("Gotohttp://www.rubyonrails.organdsayhellotodavid@loudthinking.
我正在学习http://ruby.railstutorial.org/chapters/static-pages上的RubyonRails教程并遇到以下错误StaticPagesHomepageshouldhavethecontent'SampleApp'Failure/Error:page.shouldhave_content('SampleApp')Capybara::ElementNotFound:Unabletofindxpath"/html"#(eval):2:in`text'#./spec/requests/static_pages_spec.rb:7:in`(root)'
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD