[XSLT技巧] 实现自动编号
来源:互联网 发布:卸载残留小知 编辑:程序博客网 时间:2024/05/12 09:59
下面是一个实现自动编号的例子:
test.xml:
<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<root>
<itemA>a</itemA>
<itemB>b</itemB>
<itemB>b</itemB>
<itemA>a</itemA>
<itemA>a</itemA>
<itemA>a</itemA>
<itemA>a</itemA>
<itemB>b</itemB>
<itemB>b</itemB>
<itemB>b</itemB>
<itemA>a</itemA>
<itemB>b</itemB>
<itemA>a</itemA>
<itemB>b</itemB>
</root>
test.xsl:
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="itemA">
<span style="color: blue">
<xsl:value-of select="name()"/>'s index =
<xsl:call-template name="getIndex">
<xsl:with-param name="elemName" select="name()"/>
</xsl:call-template>
</span>
<br />
</xsl:template>
<xsl:template match="itemB">
<span style="color: red">
<xsl:value-of select="name()"/>'s index =
<xsl:call-template name="getIndex">
<xsl:with-param name="elemName" select="name()"/>
</xsl:call-template>
</span>
<br />
</xsl:template>
<xsl:template name="getIndex"><!-- 获得当前层下,指定元素的序号 -->
<xsl:param name="elemName"/>
<xsl:param name="initNo">1</xsl:param> <!-- 设置初始值,默认为1。 -->
<xsl:value-of select="count(preceding-sibling::*[name()=$elemName])+number($initNo)"/>
</xsl:template>
</xsl:stylesheet>
- [XSLT技巧] 实现自动编号
- DataGrid实现自动编号
- 触发器实现自动编号
- GridView实现自动编号
- EhLib实现自动编号功能
- sqlite 自动编号的实现
- GridView控件自动编号实现
- 9.GridView实现自动编号:
- Oracle触发器实现自动编号
- WORD图片自动编号技巧[zz]
- java实现自动编号系统(类似于word中自动编号)
- (sql妙用) 实现 数据集自动编号
- 在SQL 2000中实现自动编号
- 如何实现章节标题自动编号/目录
- sql触发器实现自动编号格式
- Excel如何实现表单编号自动递增?
- .NET中GridView实现自动编号
- oracle实现table中的自动编号
- 用Python读取proxy
- 检查SQL Server事务日志大小
- MIT开放课程,好东东哦~~~
- 转[心开风神]开发Wap 中的随笔
- I was promoted for project manager 任务
- [XSLT技巧] 实现自动编号
- 自动生成数据对象代码和CRUD操作的C#代码生成器
- O/R Mapping 的故事
- YouTube在首页广告栏中展示Paris
- 在VisualC++中检测和隔离内存泄漏(转载)
- 手停口就停 让白领心力交瘁的6个城市
- .net Applcation FrameWork
- 心理测试
- 王仕鹏压哨三分 中国1分逆转晋级