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

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - Scott Xu(南方小鬼)

C#发现之旅第一讲 C#-XML开发 XPath Operators Basic XPath Axes Basic XPath Syntax Basic XPath Basic 深入浅出之正则表达式(二) 深入浅出之正则表达式(一) 通过Microsoft.Feeds获取feeds My Best Loves C#(3.0) 深入浅出系列之相关概念 C#(3.0) 深入浅出系列 Expression Studio 2.0 中文版发布了 一定能影响你的简单十句话 众说不一,“八零”后程序员到底怎么了? SQL Server 2005 实用例子 你最应该雇佣的程序员的十个特征 多个检索页面,分析,Silverlight绘图 .net component 开发系列1(学习) C# 中的设计模式3:Abstract Factory(学习笔记)
XSLT Basic
Scott Xu(南方小鬼) · 2008-08-30 · via 博客园 - Scott Xu(南方小鬼)

XSLT全称eXtended Stylesheet Language Transformation

xslt文件头:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                exclude-result-prefixes="msxsl">
  <xsl:output method="xml" indent="yes"/>

重要标签解析:

<xsl:template match="xpath">               该标签用于定义模版,同时分配给指定结点

<xsl:apply-templates select="xpath">     该标签用于指定要应用模版的结点

提示: xsl:template中可以再次使用xsl:apply-templates,用于样式的多级嵌套

实例1:

planets.xml

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="planets.xslt"?>
<planets>
  <planet color="red">
    <name>Mercury</name>
    <mass units="(Earth=1)">.0553</mass>
    <day units="days">58.65</day>
    <radius units="miles">1516</radius>
    <density units="(Earth=1)">.983</density>
    <distance units="million miles">43.4</distance>
  </planet>
  <planet color="yellow">
    <name>Venus</name>
    <mass units="(Earth=1)">.815</mass>
    <day units="days">116.75</day>
    <radius units="miles">3716</radius>
    <density units="(Earth=1)">.943</density>
    <distance units="million miles">66.8</distance>
  </planet>
</planets>

planet.xslt

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                exclude-result-prefixes="msxsl">
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="planet">
    <p>
      <xsl:value-of select="name"/>
    </p>
  </xsl:template>
</xsl:stylesheet>

以上例子中,先对所有结点使用<xsl:apply-templates>,然后再使用<xsl:template>对planet结点作处理

<xsl:value-of select="xpath">   获得结点的值

语法结构的使用

  1. 类似于if(){...}else{}的语法

    <xsl:if test="expression/condition">
    
    </xsl:if>
  2. 类似于switch(){case n: ...}的语法

    <xsl:choose>
      <xsl:when test="condition"></xsl:when>
      <xsl:when test="condition"></xsl:when>
      <xsl:otherwise></xsl:otherwise>
    </xsl:choose>
  3. foreach语法

    <xsl:for-each select="node1">
    
    </xsl:for-each>
  4. 模版函数定义

    <xsl:template name="template1">
      <xsl:param name="parameter1"/>
      <xsl:param name="parameter2" select="defaultvalue"/>
    
    </xsl:template>

    其中,parameter2使用select属性指定了默认值defaultvalue。

    对于模版函数中的参数可以用$variable来引用

    实例3:

    <xsl:call-template name="template1">
      <xsl:with-param name="parameter1"/>
    </xsl:call-template>