Xslt中属性的访问方法总结
来源:互联网 发布:cisco 清除端口配置 编辑:程序博客网 时间:2024/05/24 02:43
访问属性的方法和访问元素的方法是一样的。注意属性名前面有个"@"符号
属性和元素的处理方法是一样的。
你也可以通过是否包含某些属性值来选择元素。 XSLT stylesheet 1 选择了,而 XSLT stylesheet 2 排除了那些包含特定属性的元素。
XML源码
<source>
<dog name="Joe">
<data weight="18 kg" color="black"/>
</dog>
</source>
<dog name="Joe">
<data weight="18 kg" color="black"/>
</dog>
</source>
输出
<p>
<b>Dog: </b>Joe</p>
<p>
<b>Color: </b>black</p>
<b>Dog: </b>Joe</p>
<p>
<b>Color: </b>black</p>
用HTML察看
Dog: Joe
Color: black
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="dog">
<p>
<b>
<xsl:text>Dog: </xsl:text>
</b>
<xsl:value-of select="@name"/>
</p>
<p>
<b>
<xsl:text>Color: </xsl:text>
</b>
<xsl:value-of select="data/@color"/>
</p>
</xsl:template>
</xsl:stylesheet>
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="dog">
<p>
<b>
<xsl:text>Dog: </xsl:text>
</b>
<xsl:value-of select="@name"/>
</p>
<p>
<b>
<xsl:text>Color: </xsl:text>
</b>
<xsl:value-of select="data/@color"/>
</p>
</xsl:template>
</xsl:stylesheet>
属性和元素的处理方法是一样的。
XSLT stylesheet 1
XML源码
<source>
<employee id="js0034"> Joe Smith </employee>
</source>
<employee id="js0034"> Joe Smith </employee>
</source>
输出
Joe Smith
[<b>
<i>js0034</i>
</b>]
[<b>
<i>js0034</i>
</b>]
用HTML察看
Joe Smith [ js0034 ]
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="employee">
<xsl:value-of select="."/>
<xsl:text>[</xsl:text>
<xsl:apply-templates select="@id"/>
<xsl:text>]</xsl:text>
</xsl:template>
<xsl:template match="@id">
<b>
<i>
<xsl:value-of select="."/>
</i>
</b>
</xsl:template>
</xsl:stylesheet>
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="employee">
<xsl:value-of select="."/>
<xsl:text>[</xsl:text>
<xsl:apply-templates select="@id"/>
<xsl:text>]</xsl:text>
</xsl:template>
<xsl:template match="@id">
<b>
<i>
<xsl:value-of select="."/>
</i>
</b>
</xsl:template>
</xsl:stylesheet>
你也可以通过是否包含某些属性值来选择元素。 XSLT stylesheet 1 选择了,而 XSLT stylesheet 2 排除了那些包含特定属性的元素。
XSLT stylesheet 1
XML源码
<source>
<car id="a234" checked="yes"/>
<car id="a111" checked="yes"/>
<car id="a005"/>
</source>
<car id="a234" checked="yes"/>
<car id="a111" checked="yes"/>
<car id="a005"/>
</source>
输出
<p>Car: a234</p>
<p>Car: a111</p>
<p>Car: a111</p>
用HTML察看
Car: a234
Car: a111
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="car[@checked]">
<p>
<xsl:text>Car: </xsl:text>
<xsl:value-of select="@id"/>
</p>
</xsl:template>
</xsl:stylesheet>
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="car[@checked]">
<p>
<xsl:text>Car: </xsl:text>
<xsl:value-of select="@id"/>
</p>
</xsl:template>
</xsl:stylesheet>
XSLT stylesheet 2
XML源码
<source>
<car id="a234" checked="yes"/>
<car id="a111" checked="yes"/>
<car id="a005"/>
</source>
<car id="a234" checked="yes"/>
<car id="a111" checked="yes"/>
<car id="a005"/>
</source>
输出
<p>Car: a005</p>
用HTML察看
Car: a005
XSLT stylesheet
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="car[not(@checked)]">
<p>
<xsl:text>Car: </xsl:text>
<xsl:value-of select="@id"/>
</p>
</xsl:template>
</xsl:stylesheet>
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="car[not(@checked)]">
<p>
<xsl:text>Car: </xsl:text>
<xsl:value-of select="@id"/>
</p>
</xsl:template>
</xsl:stylesheet>
- Xslt中属性的访问方法总结
- XSLT中&的表示方法
- XSLT中访问当前系统的环境变量值和JVM系统属性
- XSLT中输出 的方法
- XSLT中 的输出方法
- Java中类的属性和方法的访问控制
- php中类外部访问类私有属性的方法
- JSP中取bean属性访问不到的问题解决方法
- xslt格式化日期的方法
- Javascript中实现跨域访问的方法总结
- ajax中常用对象的属性及方法总结
- ajax中常用对象的属性及方法总结
- JavaScript中访问id对象.属性的方式访问属性
- JNI学习总结——C/C++访问Java类的属性与方法
- 多态情况下,关于属性和方法的访问总结
- XSLT常见问题(三)XSLT中attribute的使用
- Jni访问java的属性,方法
- 访问类的方法和属性
- net开发过程中,错误集锦
- vc++ 64位长整型转换成字符串
- logic:iterate应用
- 基于DirectShow的流媒体解码和回放 (转载 作者 :刘 涛 ,天极网)
- 谈谈我为什么不用易趣和卓越
- Xslt中属性的访问方法总结
- 李开复给中国学生的第二封信:从优秀到卓越
- 【亲自动手试验过的】硬盘免光驱安装Fedora5
- 通过避免下列10个常见ASP.NET缺陷使网站平稳运行
- 李开复给中国学生的第三封信:成功、自信、快乐
- 利用GridView显示主细表并添加打开、关闭功能
- DataGrid用法集锦[收藏]
- 李开复给中国大学生的第四封信:大学4年应是这样度过
- 利用 ASP.NET 的内置功能抵御 Web 攻击