在使用XSLT实现此需求时需要一些帮助,我已经使用SAX解析器实现了此代码的Java代码,但由于客户请求改变了某些内容。XSLT:分割无继续元素/分组继续元素
所以我们现在正在使用XSLT进行编译,并且不需要编译并部署到Web服务器。我有如下的XML。
实施例1:
<ShotRows>
<ShotRow row="3" col="3" bit="1" position="1"/>
<ShotRow row="3" col="4" bit="1" position="2"/>
<ShotRow row="3" col="5" bit="1" position="3"/>
<ShotRow row="3" col="6" bit="1" position="4"/>
<ShotRow row="3" col="7" bit="1" position="5"/>
<ShotRow row="3" col="8" bit="1" position="6"/>
<ShotRow row="3" col="9" bit="1" position="7"/>
<ShotRow row="3" col="10" bit="1" position="8"/>
<ShotRow row="3" col="11" bit="1" position="9"/>
</ShotRows>
输出1:
<ShotRows>
<ShotRow row="3" colStart="3" colEnd="11" />
</ShotRows>
<!-- because the col is continuous from 3 to 11 -->
实施例2:
<ShotRows>
<ShotRow row="3" col="3" bit="1" position="1"/>
<ShotRow row="3" col="4" bit="1" position="2"/>
<ShotRow row="3" col="6" bit="1" position="3"/>
<ShotRow row="3" col="7" bit="1" position="4"/>
<ShotRow row="3" col="8" bit="1" position="5"/>
<ShotRow row="3" col="10" bit="1" position="6"/>
<ShotRow row="3" col="11" bit="1" position="7"/>
<ShotRow row="3" col="15" bit="1" position="8"/>
<ShotRow row="3" col="19" bit="1" position="9"/>
</ShotRows>
输出2:
<ShotRows>
<ShotRow row="3" colStart="3" colEnd="4" />
<ShotRow row="3" colStart="6" colEnd="8" />
<ShotRow row="3" colStart="10" colEnd="11" />
<ShotRow row="3" colStart="15" colEnd="15" />
<ShotRow row="3" colStart="19" colEnd="19" />
</ShotRows>
其基本思想是将任何连续的列组合到一个元素中,例如col 3到4,col 6到8,col 10到11,col 15只有一个,col 19只有一个。提前致谢。
简单而优雅,+1。:) – Tomalak 2010-03-08 12:34:52
XSLT 2.0也可以通过Saxon.NET在.NET中使用。 – 2010-03-08 13:40:49
我们在java中使用Saxon 9.1 – Gerald 2010-03-08 14:51:43