惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Last Watchdog
The Last Watchdog
AI
AI
Webroot Blog
Webroot Blog
aimingoo的专栏
aimingoo的专栏
Hacker News: Ask HN
Hacker News: Ask HN
B
Blog RSS Feed
小众软件
小众软件
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
W
WeLiveSecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Troy Hunt's Blog
云风的 BLOG
云风的 BLOG
P
Privacy International News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Vercel News
Vercel News
Y
Y Combinator Blog
P
Proofpoint News Feed
V2EX - 技术
V2EX - 技术
AWS News Blog
AWS News Blog
F
Fortinet All Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
A
Arctic Wolf
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
V2EX
MongoDB | Blog
MongoDB | Blog
SecWiki News
SecWiki News
The Register - Security
The Register - Security
博客园_首页
T
Threat Research - Cisco Blogs
Hacker News - Newest:
Hacker News - Newest: "LLM"
Recorded Future
Recorded Future
V
Vulnerabilities – Threatpost
I
InfoQ
雷峰网
雷峰网
C
Check Point Blog

博客园 - 过江

多线程业务实现疑问 委托的三种写法 LinqToXml学习实例 String.format使用( 转) - 过江 - 博客园 TFS 安装手册以及常用问题解决方法 SQL server 系统优化--通过执行计划优化索引(1) (转) .Net新建、卸载、调试Windows服务 请问在用C#+Mapx开始,怎样根据图元名称获得该图元已经选中的图元 C#基础:ref和out的区别 仿163邮箱的alert提示,beta1.1 (转) 好久都没有写东西了 终于用上CodeSmith4.0了,跟大家一起分享 扩展TreeView控件(1) - 联动复选框(复选框的全选和取消全选)(转) 动态地生成用户输入的函数表达式(C#) (转) 画函数图形的C#程序(改进版) (转) 画函数图形的C#程序,兼论一个病态函数 (转) 获取M$ SQL Server用户表的字段信息 (转) 关于Remoting服务启动和停止的简单总结 (转) MSMQ(3)创建、同步异步接收消息
XSLT基本语法和第一个实例
过江 · 2007-08-22 · via 博客园 - 过江

人家都说XSLT转换技术是XML的一项重要技术,俺也没有机会在项目里运用,就在网上瞎搜搜,找点学习学习,所以下面我写的自己的学习结果有可能跟哪位老兄有些许雷同,纯属巧合哈,先申明。
首先说下XSL的主要语句:

主要语句 含  义
xsl:stylesheet 声明语句
xsl:template 相当于编程中函数的概念
xsl:template match = "" 相当于函数调用,去匹配引号中指定的节点
xsl:apply-templates 应用模板函数
xsl:apply-templates select ="" 应用模板函数的调用,跳转到引号中指定的模板
xsl:for-each select = "" 循环语句,遍历与引号中的属性值相同的节点
xsl:value-of select = "" 赋值语句,取出引号中指定的属性值

上面就是最常用地语句,下面我们来看看具体的实例:
my.xml文件

<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="mystyle.xsl"?>
<Books>
    
<Book ID="a001">
      
<Type>True</Type>
        
<Name>网络指南</Name>
        
<Price>13.2</Price>
    
</Book>
    
<Book ID="a002">
    
<Type>False</Type>
        
<Name>局域网技术</Name>
        
<Price>25.5</Price>
    
</Book>
</Books>

这个就不再多说了,大家都应该知道的哈!
mystyle.xsl

<?xml version="1.0" encoding="GB2312"?>
//version-版本,encoding-语言
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">//匹配XML所有的节点
 <html>
   
<body>
    
<table border="1" bgcolor="blue">
     
<tr>
       
<th>Type1</th>
        
<th>Name</th>
         
<th>Price</th>
     
</tr>
     
<xsl:for-each select="Books/Book">
         
//循环Books/Book,可以取他的所有节点
     <tr>
    
//选择的一种
     <!--<td><xsl:if test="Type1='True'"></xsl:if></td>-->
     
<td>    
    
//选择的另一种,当Type1='True'时显示男,其它显示女
           <xsl:choose>
               
<xsl:when test="Type1='True'">
               男
               
</xsl:when>
               
<xsl:otherwise>
               女
               
</xsl:otherwise>
            
</xsl:choose>
          
</td>
       
//显示XML文件里Name节点的值
      <td><xsl:value-of select="Name"/></td>
      
<td><xsl:value-of select="Price"/></td>
     
</tr>
     
</xsl:for-each>
    
</table>
   
</body>
   
</html>  
    
</xsl:template>
</xsl:stylesheet>

之后我们用浏览器打开XML文件,出现如下结果: