我有 XML 文件,其中包含记录集,其中特定数量有时等于 0。 现在我必须摆脱那些记录集。我做了以下事情。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- delete 0-quantity records -->
<xsl:template match="/ExportData/DataSet/Tables/Table/Rows/R[productQuantityinttrue='0']"/>
</xsl:stylesheet>
它基本上是有效的:它复制除 productQuantityinttrue=0 之外的所有内容。但有时会删除不应该删除的记录集。 现在我的问题是,进行像这样的谈判是否会更好
<xsl:template match="/ExportData/DataSet/Tables/Table/Rows/R[not(productQuantityinttrue='0')]"
然后当然我必须复制那些最后一个陈述为真的那些。 有没有人有过这方面的经验?我没有发布 XML,因为它基本上是关于“否定或不否定”。
<?xml version="1.0" encoding="UTF-8"?>
<ExportData>
<TransportHeader>
<Timestamp>2011-07-28 14:16:49</Timestamp>
<From>
<Name>MFES DynamicExport Plugin</Name>
<Version>1.1.6.95</Version>
</From>
<MessageId>a46d4d6d-667e-4e74-b3c5-a6e9ecaeacb1</MessageId>
</TransportHeader>
<ExportConfig>
<DateTimeFormat>yyyy-MM-dd HH:mm:ss</DateTimeFormat>
<DecimalSymbol>.</DecimalSymbol>
</ExportConfig>
<DataSet>LSA_SALES_EXPORT <Tables>
<Table>MI_Sales <RH>
<C>companyCodestringtrue</C>
<C>storeNumstring</C>
<C>transactionDatedateTime</C>
<C>transactionQualifierIDint</C>
<C>transactionQualifierstring</C>
<C>costCenterNumberstringtrue</C>
<C>revenueCenterPOSReflongtrue</C>
<C>menuItemNumberlong</C>
<C>menuItemNameOnestring</C>
<C>menuItemNameTwostringtrue</C>
<C>crossReferenceOnestringtrue</C>
<C>crossReferenceTwostringtrue</C>
<C>consumerUnitDescriptionstringtrue</C>
<C>transactionValueInclVATdecimaltrue</C>
<C>transactionValueExclVATdecimaltrue</C>
<C>productQuantityinttrue</C>
<C>productValueInclVATdecimaltrue</C>
<C>productValueExclVATdecimaltrue</C>
<C>discountType01AmountInclVATdecimaltrue</C>
<C>discountType02AmountInclVATdecimaltrue</C>
<C>discountType03AmountInclVATdecimaltrue</C>
<C>discountType04AmountInclVATdecimaltrue</C>
<C>discountType05AmountInclVATdecimaltrue</C>
<C>discountType06AmountInclVATdecimaltrue</C>
<C>discountType07AmountInclVATdecimaltrue</C>
<C>discountType08AmountInclVATdecimaltrue</C>
<C>discountType09AmountInclVATdecimaltrue</C>
<C>discountType10AmountInclVATdecimaltrue</C>
<C>discountType01AmountExclVATdecimaltrue</C>
<C>discountType02AmountExclVATdecimaltrue</C>
<C>discountType03AmountExclVATdecimaltrue</C>
<C>discountType04AmountExclVATdecimaltrue</C>
<C>discountType05AmountExclVATdecimaltrue</C>
<C>discountType06AmountExclVATdecimaltrue</C>
<C>discountType07AmountExclVATdecimaltrue</C>
<C>discountType08AmountExclVATdecimaltrue</C>
<C>discountType09AmountExclVATdecimaltrue</C>
<C>discountType10AmountExclVATdecimaltrue</C>
<C>totalAmountDiscountInclVATdecimaltrue</C>
<C>totalAmountDiscountExclVATdecimaltrue</C>
<C>totalAmountVATdecimaltrue</C>
<C>rateAmountVATdecimaltrue</C>
<C>returnReasonCodestringtrue</C>
<C>weightdecimaltrue</C>
<C>detailTypeinttrue</C>
<C>detailPOSReflong</C>
<C>menuItemIDlong</C>
</RH>
<Rows>
<R>
<companyCodestringtrue>111</companyCodestringtrue>
<storeNumstring>6002</storeNumstring>
<transactionDatedateTime>2011-07-27 00:00:00</transactionDatedateTime>
<transactionQualifierIDint>1</transactionQualifierIDint>
<transactionQualifierstring>Sales</transactionQualifierstring>
<costCenterNumberstringtrue/>
<revenueCenterPOSReflongtrue>1000</revenueCenterPOSReflongtrue>
<menuItemNumberlong>5900003</menuItemNumberlong>
<menuItemNameOnestring>Exc X Crmy 100g.LSCA</menuItemNameOnestring>
<menuItemNameTwostringtrue>Exc X Crmy 1.LSCA</menuItemNameTwostringtrue>
<crossReferenceOnestringtrue>1110</crossReferenceOnestringtrue>
<crossReferenceTwostringtrue>037466017594</crossReferenceTwostringtrue>
<consumerUnitDescriptionstringtrue/>
<transactionValueInclVATdecimaltrue>3.69</transactionValueInclVATdecimaltrue>
<transactionValueExclVATdecimaltrue>3.69</transactionValueExclVATdecimaltrue>
<productQuantityinttrue>1</productQuantityinttrue>
<productValueInclVATdecimaltrue>3.69</productValueInclVATdecimaltrue>
<productValueExclVATdecimaltrue>3.265487</productValueExclVATdecimaltrue>
<discountType01AmountInclVATdecimaltrue/>
<discountType02AmountInclVATdecimaltrue/>
<discountType03AmountInclVATdecimaltrue/>
<discountType04AmountInclVATdecimaltrue/>
<discountType05AmountInclVATdecimaltrue/>
<discountType06AmountInclVATdecimaltrue/>
<discountType07AmountInclVATdecimaltrue/>
<discountType08AmountInclVATdecimaltrue/>
<discountType09AmountInclVATdecimaltrue/>
<discountType10AmountInclVATdecimaltrue/>
<discountType01AmountExclVATdecimaltrue/>
<discountType02AmountExclVATdecimaltrue/>
<discountType03AmountExclVATdecimaltrue/>
<discountType04AmountExclVATdecimaltrue/>
<discountType05AmountExclVATdecimaltrue/>
<discountType06AmountExclVATdecimaltrue/>
<discountType07AmountExclVATdecimaltrue/>
<discountType08AmountExclVATdecimaltrue/>
<discountType09AmountExclVATdecimaltrue/>
<discountType10AmountExclVATdecimaltrue/>
<totalAmountDiscountInclVATdecimaltrue/>
<totalAmountDiscountExclVATdecimaltrue/>
<totalAmountVATdecimaltrue>0</totalAmountVATdecimaltrue>
<rateAmountVATdecimaltrue>13</rateAmountVATdecimaltrue>
<returnReasonCodestringtrue/>
<weightdecimaltrue>0</weightdecimaltrue>
<detailTypeinttrue>1</detailTypeinttrue>
<detailPOSReflong>5900003</detailPOSReflong>
<menuItemIDlong>136577483</menuItemIDlong>
</R>
<R>
<companyCodestringtrue>111</companyCodestringtrue>
<storeNumstring>6002</storeNumstring>
<transactionDatedateTime>2011-07-27 00:00:00</transactionDatedateTime>
<transactionQualifierIDint>1</transactionQualifierIDint>
<transactionQualifierstring>Sales</transactionQualifierstring>
<costCenterNumberstringtrue/>
<revenueCenterPOSReflongtrue>1000</revenueCenterPOSReflongtrue>
<menuItemNumberlong>5900185</menuItemNumberlong>
<menuItemNameOnestring>PD MousseHzl140g.LSCA</menuItemNameOnestring>
<menuItemNameTwostringtrue>PD MousseHzl.LSCA</menuItemNameTwostringtrue>
<crossReferenceOnestringtrue>428131</crossReferenceOnestringtrue>
<crossReferenceTwostringtrue>037466083414</crossReferenceTwostringtrue>
<consumerUnitDescriptionstringtrue/>
<transactionValueInclVATdecimaltrue>0</transactionValueInclVATdecimaltrue>
<transactionValueExclVATdecimaltrue>0</transactionValueExclVATdecimaltrue>
<productQuantityinttrue>0</productQuantityinttrue>
<productValueInclVATdecimaltrue>4.99</productValueInclVATdecimaltrue>
<productValueExclVATdecimaltrue>4.415929</productValueExclVATdecimaltrue>
<discountType01AmountInclVATdecimaltrue/>
<discountType02AmountInclVATdecimaltrue/>
<discountType03AmountInclVATdecimaltrue/>
<discountType04AmountInclVATdecimaltrue/>
<discountType05AmountInclVATdecimaltrue/>
<discountType06AmountInclVATdecimaltrue/>
<discountType07AmountInclVATdecimaltrue/>
<discountType08AmountInclVATdecimaltrue/>
<discountType09AmountInclVATdecimaltrue/>
<discountType10AmountInclVATdecimaltrue/>
<discountType01AmountExclVATdecimaltrue/>
<discountType02AmountExclVATdecimaltrue/>
<discountType03AmountExclVATdecimaltrue/>
<discountType04AmountExclVATdecimaltrue/>
<discountType05AmountExclVATdecimaltrue/>
<discountType06AmountExclVATdecimaltrue/>
<discountType07AmountExclVATdecimaltrue/>
<discountType08AmountExclVATdecimaltrue/>
<discountType09AmountExclVATdecimaltrue/>
<discountType10AmountExclVATdecimaltrue/>
<totalAmountDiscountInclVATdecimaltrue/>
<totalAmountDiscountExclVATdecimaltrue/>
<totalAmountVATdecimaltrue>0</totalAmountVATdecimaltrue>
<rateAmountVATdecimaltrue>13</rateAmountVATdecimaltrue>
<returnReasonCodestringtrue/>
<weightdecimaltrue>0</weightdecimaltrue>
<detailTypeinttrue>1</detailTypeinttrue>
<detailPOSReflong>5900185</detailPOSReflong>
<menuItemIDlong>136577665</menuItemIDlong>
</R>
</Rows>
</Table>
</Tables>
最佳答案
<!-- delete 0-quantity records --> <xsl:template match="/ExportData/DataSet/Tables/Table/Rows/R[productQuantityinttrue='0']"/>It does basically work: it copies everything except the ones with productQuantityinttrue=0. But sometimes there are recordsets deleted that shouldn't be.
您没有提供重现此问题的示例。
我的猜测是您可以使用以下方法解决此问题:
<xsl:template match=
"Rows/R[not(productQuantityinttrue[2])
and
productQuantityinttrue='0'
]"/>
match 属性中的表达式仅选择只有一个 productQuantityinttrue 的 child 而这个唯一的 .../Rows/R 元素productQuantityinttrue child child 的字符串值为 '0'。
关于xml - 在条件下否定偏好吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6882610/
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
我的假设是moduleAmoduleBendend和moduleA::Bend是一样的。我能够从thisblog找到解决方案,thisSOthread和andthisSOthread.为什么以及什么时候应该更喜欢紧凑语法A::B而不是另一个,因为它显然有一个缺点?我有一种直觉,它可能与性能有关,因为在更多命名空间中查找常量需要更多计算。但是我无法通过对普通类进行基准测试来验证这一点。 最佳答案 这两种写作方法经常被混淆。首先要说的是,据我所知,没有可衡量的性能差异。(在下面的书面示例中不断查找)最明显的区别,可能也是最著名的,是你的
我的Gallery模型中有以下查询:media_items.includes(:photo,:video).rank(:position_in_gallery)我的图库模型有_许多媒体项,每个都有一个照片或视频关联。到目前为止,一切正常。它返回所有media_items包括它们的photo或video关联,由media_item的position_in_gallery属性排序。但是我现在需要将此查询返回的照片限制为仅具有is_processing属性的照片,即nil。是否可以进行相同的查询,但条件是返回的照片等同于:.where(photo:'photo.is_processingIS
除了可访问性标准不鼓励使用这一事实指向当前页面的链接,我应该怎么做重构以下View代码?#navigation%ul.tabbed-ifcurrent_page?(new_profile_path)%li{:class=>"current_page_item"}=link_tot("new_profile"),new_profile_path-else%li=link_tot("new_profile"),new_profile_path-ifcurrent_page?(profiles_path)%li{:class=>"current_page_item"}=link_tot("p
我正在尝试按Rails相关模型中的字段进行排序。我研究的所有解决方案都没有解决如果相关模型被另一个参数过滤?元素模型classItem相关模型:classPriority我正在使用where子句检索项目:@items=Item.where('company_id=?andapproved=?',@company.id,true).all我需要按相关表格中的“位置”列进行排序。问题在于,在优先级模型中,一个项目可能会被多家公司列出。因此,这些职位取决于他们拥有的company_id。当我显示项目时,它是针对一个公司的,按公司内的职位排序。完成此任务的正确方法是什么?感谢您的帮助。PS-我
基本上,我只是试图在满足特定条件时停止程序运行其余行。unlessraw_information.firstputs"Noresultswerereturnedforthatquery"breakend然而,在程序运行之前我得到了这个错误:Invalidbreakcompileerror(SyntaxError)执行此操作的正确方法是什么? 最佳答案 abort("Noresultswerereturnedforthatquery")unlesscondition或unlessconditionabort("Noresultswer
如果用户是所有者,我有一个条件来检查说删除和文章。delete_articleifuser.owner?另一种方式是user.owner?&&delete_article选择它有什么好处还是它只是一种写作风格 最佳答案 性能不太可能成为该声明的问题。第一个要好得多-它更容易阅读。您future的自己和其他将开始编写代码的人会为此感谢您。 关于ruby-on-rails-如果条件与&&,是否有任何性能提升,我们在StackOverflow上找到一个类似的问题: