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

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - 过江

多线程业务实现疑问 委托的三种写法 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文件,出现如下结果: