如何遍历 XSLT 中的以下同级
Posted
技术标签:
【中文标题】如何遍历 XSLT 中的以下同级【英文标题】:How to iterate through following sibling in XSLT 【发布时间】:2021-06-27 08:16:29 【问题描述】:我有一个看起来像的 XML
<?xml version="1.0" encoding="UTF-8"?><Rowsets >
<Rowset>
<Row>
<plant>1000</plant>
<workCenterId>10001</workCenterId>
<workCenter>WC1</workCenter>
<alerts>alerts</alerts>
<incident>incident</incident>
<dashboard>dashboard</dashboard>
<alertStatus>false</alertStatus>
<incidentStatus>false</incidentStatus>
<dashboardStatus>true</dashboardStatus>
</Row>
<Row>
<plant>1000</plant>
<workCenterId>10001</workCenterId>
<workCenter>WC1</workCenter>
<alerts>alerts</alerts>
<incident>incident</incident>
<dashboard>dashboard</dashboard>
<alertStatus>true</alertStatus>
<incidentStatus>false</incidentStatus>
<dashboardStatus>false</dashboardStatus>
</Row>
<Row>
<plant>1000</plant>
<workCenterId>10001</workCenterId>
<workCenter>WC1</workCenter>
<alerts>alerts</alerts>
<incident>incident</incident>
<dashboard>dashboard</dashboard>
<alertStatus>false</alertStatus>
<incidentStatus>true</incidentStatus>
<dashboardStatus>false</dashboardStatus>
</Row>
<Row>
<plant>1000</plant>
<workCenterId>10002</workCenterId>
<workCenter>WC2</workCenter>
<alerts>alerts</alerts>
<incident>incident</incident>
<dashboard>dashboard</dashboard>
<alertStatus>false</alertStatus>
<incidentStatus>false</incidentStatus>
<dashboardStatus>true</dashboardStatus>
</Row>
<Row>
<plant>1000</plant>
<workCenterId>10002</workCenterId>
<workCenter>WC2</workCenter>
<alerts>alerts</alerts>
<incident>incident</incident>
<dashboard>dashboard</dashboard>
<alertStatus>true</alertStatus>
<incidentStatus>false</incidentStatus>
<dashboardStatus>false</dashboardStatus>
</Row>
<Row>
<plant>1000</plant>
<workCenterId>10003</workCenterId>
<workCenter>WC3</workCenter>
<alerts>alerts</alerts>
<incident>incident</incident>
<dashboard>dashboard</dashboard>
<alertStatus>false</alertStatus>
<incidentStatus>false</incidentStatus>
<dashboardStatus>false</dashboardStatus>
</Row>
<Row>
<plant>1000</plant>
<workCenterId>10004</workCenterId>
<workCenter>WC4</workCenter>
<alerts>alerts</alerts>
<incident>incident</incident>
<dashboard>dashboard</dashboard>
<alertStatus>false</alertStatus>
<incidentStatus>false</incidentStatus>
<dashboardStatus>false</dashboardStatus>
</Row>
<Row>
<plant>1000</plant>
<workCenterId>10005</workCenterId>
<workCenter>WC4</workCenter>
<alerts>alerts</alerts>
<incident>incident</incident>
<dashboard>dashboard</dashboard>
<alertStatus>false</alertStatus>
<incidentStatus>false</incidentStatus>
<dashboardStatus>false</dashboardStatus>
</Row>
</Rowset>
我想要做的是遍历每个 Workcenter 并提取文本值“true”,无论它是否为真。在下一次迭代中,如果 workCenter 相同,再次提取文本“true”等等。
我是 XSLT 的新手,不知道兄弟节点。有人可以帮忙吗?
所有迭代后的预期输出`
<?xml version="1.0" encoding="UTF-8"?>
<root>
<WC>
<workCenter>WC1</workCenter>>
<alerts>alerts:true</alerts>
<dashboard>dashboard:true</dashboard>
<incident>incident:true</incident>
</WC>
<WC>
<workCenter>WC2</workCenter>>
<alerts>alerts:true</alerts>
<dashboard>dashboard:true</dashboard>
<incident>incident:false</incident>
</WC>
<WC>
<workCenter>WC3</workCenter>>
<alerts>alerts:false</alerts>
<dashboard>dashboard:false</dashboard>
<incident>incident:false</incident>
</WC>
<WC>
<workCenter>WC4</workCenter>>
<alerts>alerts:false</alerts>
<dashboard>dashboard:false</dashboard>
<incident>incident:false</incident>
</WC>
</root>
【问题讨论】:
这似乎是一个分组问题。 XSLT 1.0 中的首选解决方案是使用 Muenchian 分组方法:jenitennison.com/xslt/grouping/muenchian.html 【参考方案1】:这是在后端 SQL DB 中处理的
【讨论】:
这没有回答问题。如果您通过其他方式解决了问题,您可以删除问题。以上是关于如何遍历 XSLT 中的以下同级的主要内容,如果未能解决你的问题,请参考以下文章