[原创]XSL学习心得 - 调用属性值

[原创]XSL学习心得 - 调用属性值
也许这个问题很简单吧,但是刚才查了好多篇入门教程都没有涉及,幸好hsower发的xsl语法介绍中有详细的说明。

1<xsl: -of="" _value_="" select="元素名称/@属性名称"></xsl:>

比如一段XML代码是这样的:
<王朔 网址=" www.wangshuo.com ">知名作家加著名评论家王朔先生的地方

我们可以用

1<xsl: -of="" _value_="" select="王朔/@网址"></xsl:>

来得到值" www.wangshuo.com "。


下边是我自己写的一个例子,供大家参考。
my.xml
以下内容为程序代码:

 1<books>
 2<book id="a001">
 3<name>网络指南</name>
 4<price>13.2</price>
 5</book>
 6<book id="a002">
 7<name>局域网技术</name>
 8<price>25.5</price>
 9</book>
10</books>

mystyle.xsl
以下内容为程序代码:

1<xsl:stylesheet version="1.0" xmlns:xsl="  http://www.w3.org/1999/XSL/Transform">
2<xsl:template match="Books/Book/*">
3<xsl: -of="" _value_="" select="./@ID"></xsl:>
4</xsl:template>
5</xsl:stylesheet>

网页浏览结果:
a001
a002

Published At
Categories with Web编程
Tagged with
comments powered by Disqus