我有一个XSLT文件,以便转换大量的数据.我想加一个"分裂"的功能,无论是作为一个链接的XSLT或者当前XSLT,它可以创建多个输出文件,以便限制在一定的阈值的文件的大小之内.我们假设输入XML如下:
<People>
<Person>
<name>John</name>
<date>June12</date>
<workTime taskID="1">34</workTime>
<workTime taskID="2">12</workTime>
</Person>
<Person>
<name>John</name>
<date>June13</date>
<workTime taskID="1">21</workTime>
<workTime taskID="2">11</workTime>
</Person>
<Person>
<name>Jack</name>
<date>June19</date>
<workTime taskID="1">20</workTime>
<workTime taskID="2">30</workTime>
</Person>
</People>
Run Code Online (Sandbox Code Playgroud)
使用muenchian分组,XSLT文件如下所示.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="PersonTasks" match="workTime" use="concat(@taskID, ../name)"/>
<xsl:template match="/">
<People>
<xsl:apply-templates select="//workTime[generate-id() = generate-id(key('PersonTasks',concat(@taskID, ../name))[1])]"/>
</People>
</xsl:template>
<xsl:template match="workTime">
<xsl:variable name="taskID">
<xsl:value-of select="@taskID"/>
</xsl:variable>
<xsl:variable name="name">
<xsl:value-of select="../name"/>
</xsl:variable>
<Person>
<name>
<xsl:value-of select="$name"/>
</name>
<taskID>
<xsl:value-of select="$taskID"/>
</taskID>
<xsl:for-each select="//workTime[../name = $name][@taskID = $taskID]">
<workTime>
<date>
<xsl:value-of select="../date"/>
</date>
<time>
<xsl:value-of …Run Code Online (Sandbox Code Playgroud) 我想使用 jQuery 选择并返回搜索到的文本。
问题是; 部分文本可能位于<span>或其他内联元素中,因此'waffles are tasty'在此文本中搜索时:'I'm not sure about <i>cabbages</i>, but <b>waffles</b> <span>are</span> <i>tasty</i>, indeed.',您不会得到任何匹配项,而文本对人们来说是不间断的。
让我们以这个 HTML 为例:
<div id="parent">
<span style="font-size: 1.2em">
I
</span>
like turtles
<span>
quite a
</span>
lot, actually.
<span>
there's loads of
</span>
tortoises over there, OMG
<div id="child">
<span style="font-size: 1.2em">
I
</span>
like turtles
<span>
quite a
</span>
lot, actually.
TURTLES!
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
使用这个(或类似的)JavaScript:
$('div#parent').selectText({query: ['i like', 'turtles', 'loads of tortoises'], caseinsensitive: true}).each(function () {
$(this).css('background-color', …Run Code Online (Sandbox Code Playgroud) 我知道论坛上有类似的问题,但似乎没有一个能完全解决我的问题。现在我对 Java 8 很陌生,所以请耐心等待。我有一个产品列表,例如:
Input:
name category type cost
prod1 cat2 t1 100.23
prod2 cat1 t2 50.23
prod1 cat1 t3 200.23
prod3 cat2 t1 150.23
prod1 cat2 t1 100.23
Output:
Single line (name, category, type) summing the cost and count of products.
Product {
public String name;
public String category;
public String type;
public int id;
public double cost;
}
Run Code Online (Sandbox Code Playgroud)
我需要按名称、类别和类型对其进行分组,并生成一个汇总此数据的结果,并生成每个产品的总成本和数量。大多数示例显示按两个字段分组并使用单个条件聚合。
根据论坛上的建议,我想出了这个分组:
public class ObjectKeys {
ArrayList<Object> keys;
public ObjectKeys(Object...searchKeys) {
keys = new ArrayList<Object>();
for (int i = 0; …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有 3 种不同的方法。都回来了CompletableFuture<SomeType>。我想并行执行方法 1 和方法 2。完成方法 1 和方法 2 后,我想使用方法 1 和方法 2 返回值的参数触发方法 3。
代码示例:
CompletableFuture<Request> future1 = RequestConverter.Convert(requestDto);
CompletableFuture<String> future2 = tokenProvider.getAuthToken();
CompletableFuture<CompletableFuture<String>> future3 =
future1.thenCombine(future2,(request,token) ->
requestProcessor.Process(request,token));
Run Code Online (Sandbox Code Playgroud)
但是,与上面的代码的问题是,我得到一个CompletableFuture的CompletableFuture。我想避免这种情况并获得简单CompletableFuture<String>而不阻塞。这可能吗?
java parallel-processing nonblocking chaining completable-future
我确实有一堂课:
class BaseModel:
def __init__(self):
pass
def read_data(self):
df = ...
return df
def transform_input(self, df):
df = ...
return df
def execute(self, df):
df = ...
return df
def run(self):
data = self.read_data()
data = self.transform_input(data)
data = self.execute(data)
Run Code Online (Sandbox Code Playgroud)
如何避免这些方法相继调用?是否可以这样做:
data = self.read_data().transform_input().execute()
Run Code Online (Sandbox Code Playgroud)
?
是否可以以某种方式链接这些方法并解决在此方法链中传递参数(数据)的问题?
对于我正在进行的一个项目,我和我的团队正在使用 Angular 7。我们对 Angular 7 有点陌生,所以我们都在合作学习一些东西是如何工作的,与我们已经使用过的 AngularJS 相比使用了几年。
我正在阅读Observables 中关于反模式的一些建议,并注意到如下示例:
this.http.get<MyRadModel>(`api/example/rad/${this.someId}`)
.mergeMap(radResult => {
// ... Instructions ...
return this.http.get<SomeOtherModel>(`api/example/other/${radResult.something}`)
})
.subscribe(otherResult => {
// ... Chained instructions! ...
});
Run Code Online (Sandbox Code Playgroud)
不用说,.pipe()由于 RxJS 的变化,你必须在 Angular 6+ 中使用它,所以实际应用它看起来有点不同......
this.http.get<MyRadModel>(`api/example/rad/${this.someId}`)
.pipe(
mergeMap(radResult => {
// ... Instructions ...
// Problem #1: 'Property something does not exist on radResult'.
// ... It actually *does*.
return this.http.get<SomeOtherModel>(`api/example/other/${radResult.something}`);
}
)
.subscribe(otherResult => {
// ... Chained instructions ...
});
Run Code Online (Sandbox Code Playgroud)
我注意到的一个问题是, …
我有一些代码在长属性链的末尾提取一个值,其中任何一个属性都可以为null.
例如:
var value = prop1.prop2.prop3.prop4;
Run Code Online (Sandbox Code Playgroud)
为了在prop1中处理null的可能性,我必须写:
var value = prop1 == null ? null : prop1.prop2.prop3.prop4;
Run Code Online (Sandbox Code Playgroud)
为了在prop1和prop2中处理null的可能性,我必须写:
var value = prop1 == null
? null
: prop1.prop2 == null ? null : prop1.prop2.prop3.prop4;
Run Code Online (Sandbox Code Playgroud)
要么
var value = prop1 != null && prop1.prop2 != null
? prop1.prop2.prop3.prop4
: null;
Run Code Online (Sandbox Code Playgroud)
如果我想在prop1,prop2和prop3中处理null的可能性,或者甚至更长的属性链,那么代码开始变得非常疯狂.
必须有更好的方法来做到这一点.
如何处理属性链,以便在遇到null时返回null?
有点像?? 运营商会很棒.
我正在创建一个JavaScript库.我一直在尝试实施链接.
0:我第一次提出的:
function V(p) {
return {
add : function(addend) { return V(p + addend); },
sub : function(subtra) { return V(p - subtra); },
};
}
Run Code Online (Sandbox Code Playgroud)
使用这种方法我可以很容易地链接:
V(3).add(7).sub(5) // V(5)
Run Code Online (Sandbox Code Playgroud)
不幸的是,结果始终是一个包装的V()函数,我无法以这种方式提取结果值.所以我想了一下这个问题并提出了两个半解决方案.
1:将标志传递给最后一个方法
function V(p, flag) {
if(flag)
return p;
else
return {
add : function(addend, flag) { return V(p + addend, flag); },
sub : function(subtra, flag) { return V(p - subtra, flag); }
};
}
Run Code Online (Sandbox Code Playgroud)
使用这种方法,我可以通过将标志传递给我使用的最后一个方法来结束链:
V(3).add(7).sub(5, true) // 5
Run Code Online (Sandbox Code Playgroud)
虽然这很好用,但它需要重复一些代码,并且链接的可读性会降低,而且代码也不那么优雅.
2:使用start()和end()方法
_chain = false;
function V(p) { …Run Code Online (Sandbox Code Playgroud) 我有3个UILabels我希望在几秒钟后一个接一个地淡出.我的问题是这些都是一下子发生的.我试图链接动画,但我不能让它工作.我尝试了各种各样的建议,但无济于事.我知道这不可能很难.我最好想用一种动画方法将它们捆绑在一起,因为我想animationDidStop在显示所有3个标签之后触发其他功能.任何帮助或建议?
这是我的代码:
- (void)viewDidLoad
{
[self fadeAnimation:@"fadeAnimation" finished:YES target:lblReady];
[self fadeAnimation:@"fadeAnimation" finished:YES target:lblSet];
[self fadeAnimation:@"fadeAnimation" finished:YES target:lblGo];
}
- (void)fadeAnimation:(NSString *)animationID finished:(BOOL)finished target:(UIView *)target
{
[UIView beginAnimations:nil context:nil];
[UIView beginAnimations:animationID context:(__bridge void *)(target)];
[UIView setAnimationDuration:2];
[target setAlpha:0.0f];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud) 当我尝试使用我的自定义mixin扩展lodash时,我在使用Lodash时遇到问题.
我不成功的尝试:
假设我使用mixins为lodash添加一个新函数,如下所示:
//lodashMixins.ts
import * as _ from "lodash";
_.mixin({
swap
});
function swap(array: Array<any>, index1: number, index2: number) {
let temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
return array;
}
Run Code Online (Sandbox Code Playgroud)
如果我在其他文件中,该功能swap不可用._import _ from "lodash";
部分成功的尝试:
于是我找了帮助,人们提出来extend _.LoDashStatic,然后导出_作为新的扩展interface.
然后我做了以下事情:
//lodashMixins.ts
import * as _ from "lodash";
interface LodashExtended extends _.LoDashStatic {
swap(array: Array<any>, index1: number, index2: number): Array<any>;
}
_.mixin({
swap
});
function swap(array: Array<any>, …Run Code Online (Sandbox Code Playgroud) chaining ×10
javascript ×3
angular ×1
animation ×1
c# ×1
c#-4.0 ×1
collectors ×1
ios ×1
java ×1
java-8 ×1
java-stream ×1
jquery ×1
lambda ×1
lodash ×1
mixins ×1
nonblocking ×1
null ×1
objective-c ×1
observable ×1
oop ×1
properties ×1
python ×1
selection ×1
split ×1
text ×1
typescript ×1
xslt ×1
xslt-1.0 ×1