在XSLT 2.0中对变量进行分组(Grouping of variables in XSLT 2.0)
对于具有相同
<CtryCd>
值的每个<LineDetail>
节点,并使用<Amt>
的总和填充1<LineDetail>
<Amt>
。 但是,我还需要检查<SI>
和<TI>
节点。 求和的输出标记将基于<SI>
和<TI>
节点。 如果<SI>
和<TI>
的值均为假,则生成<Amt2>
,而如果<SI>
值为真且<TI>
为假,则生成<Amt2>
。 我创建了一个XSLT并且已经得到了总结。 但是我的输出中仍然缺少一些东西。这是一个示例XML:
<Record> <Data> <Process> <Header> <ID>22-BBB</ID> <Date>2017-02-14</Date> <ContactName>Abegail</ContactName> <!-- some other elements --> </Header> <Detail> <ID>22-CCC</ID> <RequestedDate>2017-02-14</RequestedDate> <!-- some other elements --> <LineDetail> <CtryCd>AF</CtryCd> <SI>false</SI> <TI>false</TI> <Amt>11.11</Amt> </LineDetail> <LineDetail> <CtryCd>SE</CtryCd> <SI>true</SI> <TI>false</TI> <Amt>22.22</Amt> </LineDetail> <LineDetail> <CtryCd>AF</CtryCd> <SI>false</SI> <TI>false</TI> <Amt>33.33</Amt> </LineDetail> <LineDetail> <CtryCd>AF</CtryCd> <SI>true</SI> <TI>false</TI> <Amt>55.55</Amt> </LineDetail> </Detail> </Process> </Data> </Record>
生成的输出:
<Record> <Data> <Process> <Header> <ID>22-BBB</ID> <Date>2017-02-14</Date> <ContactName>Abegail</ContactName> <!-- some other elements --> </Header> <Detail> <LineDetail> <CtryCd>AF</CtryCd> <Amt1>99.99</Amt1> </LineDetail> </Detail> <Detail> <LineDetail> <C<Amt2>22.22</Amt2> </LineDetail> </Detail> </Process> </Data> </Record>
预期产量:
<Record> <Data> <Process> <Header> <ID>22-BBB</ID> <Date>2017-02-14</Date> <ContactName>Abegail</ContactName> <!-- some other elements --> </Header> <Detail> <ID>22-CCC</ID> <RequestedDate>2017-02-14</RequestedDate> <!-- some other elements --> <LineDetail> <CtryCd>AF</CtryCd> <Amt1>44.44</<Amt1> <Amt2>55.55</Amt2> </LineDetail> <LineDetail> <CtryCd>SE</CtryCd> <Amt1>0</<Amt1> <Amt2>22.22</Amt2> </LineDetail> </Detail> </Process> </Data> </Record>
XSLT:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="CtryCd" match="LineDetail" use="CtryCd"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="Detail"> <xsl:for-each-group select="LineDetail" group-by="CtryCd"> <Detail> <LineDetail> <CtryCd> <xsl:value-of select="CtryCd"/> </CtryCd> <xsl:if test="lower-case(SI)='false' and lower-case(TI)='false'"> <Amt1> <xsl:value-of select="sum(current-group()/Amt)"/> </Amt1> <xsl:if test="lower-case(SI)='true' and lower-case(TI)='false'"> <Amt2> <xsl:value-of select="sum(current-group()/Amt)"/> </Amt2> </xsl:if> </xsl:if> <xsl:if test="lower-case(SI)='true' and lower-case(TI)='false'"> <Amt2> <xsl:value-of select="sum(current-group()/Amt)"/> </Amt2> </xsl:if> </LineDetail> </Detail> </xsl:for-each-group> </xsl:template> </xsl:stylesheet>
For each
<LineDetail>
node that has the same value of<CtryCd>
and populates 1<LineDetail>
with the summation of<Amt>
. But, I need to check also the<SI>
and<TI>
node. The output tag of the summation will be based from the<SI>
and<TI>
node. The<Amt1>
will generate if the value of<SI>
and<TI>
are both false, while<Amt2>
will generate if the value of<SI>
is true and<TI>
is false. I created an XSLT and already got the summation. But there's still something missing in my output.This is a sample XML:
<Record> <Data> <Process> <Header> <ID>22-BBB</ID> <Date>2017-02-14</Date> <ContactName>Abegail</ContactName> <!-- some other elements --> </Header> <Detail> <ID>22-CCC</ID> <RequestedDate>2017-02-14</RequestedDate> <!-- some other elements --> <LineDetail> <CtryCd>AF</CtryCd> <SI>false</SI> <TI>false</TI> <Amt>11.11</Amt> </LineDetail> <LineDetail> <CtryCd>SE</CtryCd> <SI>true</SI> <TI>false</TI> <Amt>22.22</Amt> </LineDetail> <LineDetail> <CtryCd>AF</CtryCd> <SI>false</SI> <TI>false</TI> <Amt>33.33</Amt> </LineDetail> <LineDetail> <CtryCd>AF</CtryCd> <SI>true</SI> <TI>false</TI> <Amt>55.55</Amt> </LineDetail> </Detail> </Process> </Data> </Record>
Generated output:
<Record> <Data> <Process> <Header> <ID>22-BBB</ID> <Date>2017-02-14</Date> <ContactName>Abegail</ContactName> <!-- some other elements --> </Header> <Detail> <LineDetail> <CtryCd>AF</CtryCd> <Amt1>99.99</Amt1> </LineDetail> </Detail> <Detail> <LineDetail> <C<Amt2>22.22</Amt2> </LineDetail> </Detail> </Process> </Data> </Record>
Expected output:
<Record> <Data> <Process> <Header> <ID>22-BBB</ID> <Date>2017-02-14</Date> <ContactName>Abegail</ContactName> <!-- some other elements --> </Header> <Detail> <ID>22-CCC</ID> <RequestedDate>2017-02-14</RequestedDate> <!-- some other elements --> <LineDetail> <CtryCd>AF</CtryCd> <Amt1>44.44</<Amt1> <Amt2>55.55</Amt2> </LineDetail> <LineDetail> <CtryCd>SE</CtryCd> <Amt1>0</<Amt1> <Amt2>22.22</Amt2> </LineDetail> </Detail> </Process> </Data> </Record>
XSLT:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="CtryCd" match="LineDetail" use="CtryCd"/> <!-- identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="Detail"> <xsl:for-each-group select="LineDetail" group-by="CtryCd"> <Detail> <LineDetail> <CtryCd> <xsl:value-of select="CtryCd"/> </CtryCd> <xsl:if test="lower-case(SI)='false' and lower-case(TI)='false'"> <Amt1> <xsl:value-of select="sum(current-group()/Amt)"/> </Amt1> <xsl:if test="lower-case(SI)='true' and lower-case(TI)='false'"> <Amt2> <xsl:value-of select="sum(current-group()/Amt)"/> </Amt2> </xsl:if> </xsl:if> <xsl:if test="lower-case(SI)='true' and lower-case(TI)='false'"> <Amt2> <xsl:value-of select="sum(current-group()/Amt)"/> </Amt2> </xsl:if> </LineDetail> </Detail> </xsl:for-each-group> </xsl:template> </xsl:stylesheet>
原文:https://stackoverflow.com/questions/42240723
最满意答案
它都是非常实现的定义,但通常,编译器会将
Derived
为Base1: vptr Base1: data Base2: vptr Base2: data Derived: data
Derived
的地址是整体的地址,因此物理地址与Base1
地址相同。Derived
的vtable的初始部分与Base1
的初始部分相同,而Base1:vptr实际上将指向Derived
的vtable。如果在声明中反转
Base1
和Base2
,编译器将在上面反转它们的角色。 (通常。标准中没有任何内容可以阻止编译器按字母顺序排列基数,或者将派生数据放在第一位,但我从来没有听说过编译器会这样做。)It's all very implementation defined, but typically, a compiler will lay out
Derived
asBase1: vptr Base1: data Base2: vptr Base2: data Derived: data
The address of the
Derived
is the address of the whole, thus the same physical address as that ofBase1
. The initial part of the vtable forDerived
will be identical with that ofBase1
, and the Base1: vptr will in fact point to the vtable ofDerived
.If you inverse
Base1
andBase2
in the declaration, the compiler will inverse their roles above. (Typically. There's nothing in the standard which would prevent the compiler from arranging the bases in alphabetical order, or putting the derived data first, but I've never heard of a compiler which did so.)
相关问答
更多-
它的实现已定义。 C ++ 11在标准的实现数量部分给出了建议的最小值: - 直接和间接基类[16 384]。 - 单个类的直接基类[1 024]。 [...] - 一个班级的直接和间接虚拟基地[1 024]。 我会说这非常慷慨。 It's implementation defined. C++11 gives recommended minimums in the Implementation quantities section of the standard: — Direct and indirec ...
-
C中的多重继承(Multiple Inheritance in C)[2022-05-18]
调用这种“多重继承”可能会让人感到困惑,因为多重继承是面向对象的编程问题,而C语言中不存在这种问题。 在我看来,您的困难可能是您正在尝试#include可执行代码(即.c文件),而不是链接.c文件和#including标头( .h )文件,这些文件为.c的函数提供声明。文件。 Calling this "multiple inheritance" may be confusing because multiple inheritance is an object-oriented programming i ... -
Objective-C不支持多重继承,因此这是不可能的。 继承是一种“is-a”关系,一个类只能通过继承拥有一个is-a关系。 您可以通过协议(Java或C#parlace中的接口,或C ++中的完全抽象类)拥有多个is-a关系。 您可以使用is-a关系来模拟“has-a”关系,而不是is-a关系。 任何对象都可以有任意数量的has-a关系。 在实践中,您只需要拥有所需的每个类的一个实例变量。 例如: @interface A : NSObject { @private B* _b; C ...
-
回答NO。 在java中只存在简单继承。 public class A { // Extends from `Object` class } class B extends A { // Extends from `A` } class C extends B { // Extends from `B` } 你在这里有什么 C是B,B是A,A是对象 (C是传递性的A) 多重继承 C is a B and also is a D, D is an object, B is a A , A is an ...
-
Java(与C ++不同)不允许多 态 继承 状态 ,因此不会遭受钻石问题的困扰 。 它允许通过接口多种类型的继承(一个类可以实现多个接口)。 从Java 8开始,通过接口中的default方法还有多个行为继承。 Java (unlike C++) does not allow multiple inheritance of state and, therefore, does not suffer from a diamond problem. It allows multiple inheritance ...
-
有一件事,你可以使用多重继承for mixins 。 您可以使用mixins为在另一个类(要混合的类)中定义的类添加功能。 一个特别关于C ++中mixin的链接: MixinsForCeePlusPlus One thing that you can use multiple inheritance for is for mixins. You can use mixins to add functionality to a class that is defined in another class ( ...
-
您不需要任何函数,因为C只从A和B派生一次。除非您多次从A或B派生(没有虚拟继承),否则您只需要使用: A *pbb = pc; B *pba = pc; AtoC和BtoC只有通过以下方式才能安全: C *c = dynamic_cast
(a_or_b_pointer); You don't need any function, since C only derives once from A and B. Unless you derive from A or B multiple time ... -
“多重继承通常是代码设计错误的标志” - 纯接口的父级不计入此规则。 您的I*类是纯接口(仅包含纯虚函数),因此您可以在这方面使用Digital*Point类 "multiple inheritance is typically a sign of a bad code design" - parents that are pure interfaces are not counted in regards to this rule. Your I* classes are pure interfaces ...
-
它都是非常实现的定义,但通常,编译器会将Derived为 Base1: vptr Base1: data Base2: vptr Base2: data Derived: data Derived的地址是整体的地址,因此物理地址与Base1地址相同。 Derived的vtable的初始部分与Base1的初始部分相同,而Base1:vptr实际上将指向Derived的vtable。 如果在声明中反转Base1和Base2 ,编译器将在上面反转它们的角色。 (通常。标准中没有任何内容可以阻止编译器按字母顺序排 ...
-
多重继承并不难添加,这么多语言不包含它的原因是因为它有点深奥和混乱。 多重继承通常会混淆代码,导致封装不良,并使代码行为不可预测。 通常,在代码中允许多重继承只会导致大量错误的编程来自该语言,通常会导致语言声誉不佳。 如果由于某种原因需要多重继承,那么一个聪明到能够正确使用它的编码器很可能足够聪明地编写自己的方法来实现它。 Multiple inheritance is not hard to add, the reason why so many languages don't include it is ...