我在 XSLT 下编写以实现我的报告要求所需的翻译。
虽然,输入和输出 XML 是不言自明的,但简而言之,要求是通过合并由公共属性相关的不同节点对,从现有 XML 构建新的 XML。
输入文件
<?xml version="1.0" encoding="utf-8"?>
<dataset xmlns="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<crosstab>
<values>
<value row="R1" col="C1">111</value>
<value row="R1" col="C2">222</value>
<value row="R1" col="C3">333</value>
<value row="R1" col="C4">444</value>
<value row="R1" col="C5">555</value>
<value row="R1" col="C6">666</value>
<value row="R1" col="C7">777</value>
</values>
<corner>
<caption>Number of Employees</caption>
</corner>
<columns>
<colEdge>
<caption>2010</caption>
<colEdge id="C1">
<caption>October</caption>
</colEdge>
<colEdge id="C2">
<caption>November</caption>
</colEdge>
<colEdge id="C3">
<caption>December</caption>
</colEdge>
</colEdge>
<colEdge>
<caption>2011</caption>
<colEdge id="C4">
<caption>January</caption>
</colEdge>
<colEdge id="C5">
<caption>February</caption>
</colEdge>
<colEdge id="C6">
<caption>March</caption>
</colEdge>
<colEdge id="C7">
<caption>April</caption>
</colEdge>
</colEdge>
</columns>
<rows>
</rows>
输出文件
<?xml version="1.0" encoding="utf-8"?>
<dataset xmlns:c="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<crosstab>
<values>
<value col="October 2010">111</value>
<value col="November 2010">222</value>
<value col="December 2010">333</value>
<value col="January 2011">444</value>
<value col="February 2011">555</value>
<value col="March 2011">666</value>
<value col="April 2011">777</value>
</values>
<corner>
<caption>Number of Employees</caption>
</corner>
</crosstab>
</dataset>