这是另一个令人兴奋的问题,也许对您来说很简单。
我有两个列表,一个是将项目 ID 连接到组 ID 的映射,第二个是具有简单值的项目列表。我需要将项目值的数量累加到组总计中。最初这两个列表基于不同的 XML 文件。
<!-- List 1 mapping-->
<mapping>
<sub id="1" item="a" group="a">
<sub id="2" item="b" group="a">
<sub id="3" item="d" group="b">
<sub id="4" item="e" group="b">
<sub id="5" item="f" group="c">
</mapping>
<!-- List 2 items -->
<items>
<item id="a" val="OK"/>
<item id="b" val="ERROR"/>
<item id="c" val="OK"/>
<item id="d" val="OK"/>
<item id="e" val="OK"/>
<item id="f" val="OK"/>
</items>
我目前的做法:
<xsl:variable name="failed-total">
<xsl:variable name="groups-total">
<xsl:value-of select="count(mapping//sub[not(@group=preceding-sibling::sub/@group)])"/>
</xsl:variable>
<!--Selecting the unique groups of the first list:-->
<xsl:for-each select="mapping//sub[not(@group=preceding-sibling::sub/@group)]">
<xsl:variable name="failed">
<xsl:value-of select="items/item[@id=current()/@item and val='ERROR']"/>
</xsl:variable>
<!-- TODO: add value of failed to failed-total value -->
</xsl:for-each>
需要的输出:
Number of Groups: 3
Groups failed: 1
将列表 2 更改为以下内容:
<!-- List 2 items -->
<items>
<item id="a" val="ERROR"/>
<item id="b" val="ERROR"/>
<item id="c" val="OK"/>
<item id="d" val="OK"/>
<item id="e" val="OK"/>
<item id="f" val="OK"/>
</items>
那么应该输出相同的,因为item a和be在同一组:
Number of Groups: 3
Groups failed: 1
欢迎任何提示。
最佳答案
假设您提供的所有 XML 都在单个输入 XML 文档中(您的问题并不完全清楚)这应该有效:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes"/>
<xsl:key name="kGroup" match="mapping/sub" use="@group" />
<xsl:key name="kFailedItem" match="items/item[@val = 'ERROR']" use="@id" />
<xsl:template match="/*">
<xsl:variable name="distinctGroups"
select="mapping/sub[generate-id() =
generate-id(key('kGroup', @group)[1])]" />
<xsl:variable name="failedGroups"
select="$distinctGroups[key('kGroup', @group)
[key('kFailedItem', @item)]
]" />
<xsl:value-of select="concat('Number of Groups: ', count($distinctGroups))"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="concat('Groups Failed: ', count($failedGroups))"/>
</xsl:template>
</xsl:stylesheet>
在此输入上运行时:
<root>
<!-- List 1 mapping-->
<mapping>
<sub id="1" item="a" group="a"/>
<sub id="2" item="b" group="a"/>
<sub id="3" item="d" group="b"/>
<sub id="4" item="e" group="b"/>
<sub id="5" item="f" group="c"/>
</mapping>
<!-- List 2 items -->
<items>
<item id="a" val="OK"/>
<item id="b" val="ERROR"/>
<item id="c" val="OK"/>
<item id="d" val="OK"/>
<item id="e" val="OK"/>
<item id="f" val="OK"/>
</items>
</root>
结果是:
Number of Groups: 3
Groups Failed: 1
当 mapping 和 items 元素存储在来自不同 XML 文档的单独变量中时,您可以使用以下方法:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common">
<xsl:output method="text" indent="yes"/>
<xsl:key name="kGroup" match="mapping/sub" use="@group" />
<xsl:variable name="failedItems" select="$items/items/item[@val = 'ERROR']" />
<xsl:template match="/">
<!-- Jump into the $mappings variable context -->
<xsl:apply-templates select="$mappings/mapping" />
</xsl:template>
<xsl:template match="mapping">
<xsl:variable name="distinctGroups"
select="sub[generate-id() =
generate-id(key('kGroup', @group)[1])]" />
<xsl:variable name="failedGroups"
select="$distinctGroups
[key('kGroup', @group)/@item = $failedItems/@id]" />
<xsl:value-of select="concat('Number of Groups: ', count($distinctGroups))"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="concat('Groups Failed: ', count($failedGroups))"/>
</xsl:template>
<!-- NOTE: The definitions for the four variables below are just for
demonstration purposes. In reality, I believe that your
$mappings and $items variables would be populated some
other way. -->
<xsl:variable name="mappingsNF">
<mapping>
<sub id="1" item="a" group="a"/>
<sub id="2" item="b" group="a"/>
<sub id="3" item="d" group="b"/>
<sub id="4" item="e" group="b"/>
<sub id="5" item="f" group="c"/>
</mapping>
</xsl:variable>
<xsl:variable name="mappings" select="exslt:node-set($mappingsNF)" />
<xsl:variable name="itemsNF">
<items>
<item id="a" val="OK"/>
<item id="b" val="ERROR"/>
<item id="c" val="OK"/>
<item id="d" val="OK"/>
<item id="e" val="OK"/>
<item id="f" val="OK"/>
</items>
</xsl:variable>
<xsl:variable name="items" select="exslt:node-set($itemsNF)" />
</xsl:stylesheet>
关于xml - XSLT Select 将数据分组到两个不同的列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16056956/
在控制台中反复尝试之后,我想到了这种方法,可以按发生日期对类似activerecord的(Mongoid)对象进行分组。我不确定这是完成此任务的最佳方法,但它确实有效。有没有人有更好的建议,或者这是一个很好的方法?#eventsisanarrayofactiverecord-likeobjectsthatincludeatimeattributeevents.map{|event|#converteventsarrayintoanarrayofhasheswiththedayofthemonthandtheevent{:number=>event.time.day,:event=>ev
我主要使用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代码修改为
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
我正在阅读一本关于Ruby的书,作者在编写类初始化定义时使用的形式与他在本书前几节中使用的形式略有不同。它看起来像这样:classTicketattr_accessor:venue,:datedefinitialize(venue,date)self.venue=venueself.date=dateendend在本书的前几节中,它的定义如下:classTicketattr_accessor:venue,:datedefinitialize(venue,date)@venue=venue@date=dateendend在第一个示例中使用setter方法与在第二个示例中使用实例变量之间是
我正在尝试使用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
本教程将在Unity3D中混合Optitrack与数据手套的数据流,在人体运动的基础上,添加双手手指部分的运动。双手手背的角度仍由Optitrack提供,数据手套提供双手手指的角度。 01 客户端软件分别安装MotiveBody与MotionVenus并校准人体与数据手套。MotiveBodyMotionVenus数据手套使用、校准流程参照:https://gitee.com/foheart_1/foheart-h1-data-summary.git02 数据转发打开MotiveBody软件的Streaming,开始向Unity3D广播数据;MotionVenus中设置->选项选择Unit