博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Umbraco XSLT
阅读量:7238 次
发布时间:2019-06-29

本文共 4281 字,大约阅读时间需要 14 分钟。

Supported by

I will introduce XSLT around Umbraco to help you understand it quickly. I will appreciate if you have any feedbacks on the article.

The article includes following points.

  1. What are we building?
  2. What’s the XML that will be transformed by the XSLT files in Umbraco?
  3. Commonly used attributes in Umbaco xslt.
  4. Commonly used operators in xsl
  5. Commonly used xsl functions
  6. What are the common tasks in coding with XSLT in Umbraco?

What are we building

We are building templates to transform xml datasource to html. It is powered by XSL(Extensible Stylesheet Language).

XSLT is heavily used in Umbraco. You can see it in building menus, news list, image gallery or any forms of representation in html.

You can add XSLT in Developers->XSLT Files in Umbraco backoffice, and then use  XSLT script by Umbraco macro.

Umbraco has shipped with XSLT files for most requirement that can be used with little modification. Those files are helpful to you to understand the XSLT in Umbraco as well.

What’s the XML that will be transformed by the XSLT files in Umbraco

  1. umbraco.config in App_Data.
  2. collection returned by xslt extension functions. It is recommended to define the returned datatype as System.Xml.XPath.XPathNodeIterator.

Common used attributes in Umbraco xslt

@id: used for computing the url for the content. Commonly used as following.

<a href=’umbraco.library:NiceUrl(@id)’ />

@isDoc: used for indicating is the current node is just content or associated with template. If false, indicating it is content associated with template. Commonly used in generating menus.

<xsl:for-each select=”$currentPage/*[not(@isDoc)]”>

@level: used for indicating the level number of current node in the tree nodes, starting with 1. Commonly used in generating menus.

<xsl:for-each select=”$currentPage/*[not(@isDoc) and @level = 2]”>

@nodeName: used for indicating the name of the node. Commonly used in generating menus.

<xsl:for-each select=”$currentPage/*[not(@isDoc) and @level = 2]”>

<li><xsl:value-of select=”@nodeName”/></li>

</xsl:for-each>

 

Commonly used operators in xsl

plus +
minus -
multiply *
division div
mod mod
and and
or or
not not()

 

Commonly used functions in xsl

position(): return the index of the current node in for-each

current(): return the current node

name(): return the name of the current node or the first node in the specified node set. It is heavily used in the xslt for related links.

<xsl:for-each select=”$currentPage/*[name()=@propertyAlias]/links/link”>

</xsl:for-each>

count(“expression”): return the number of the elements in the expression

Please refer to and for more functions.

What’s the common task in coding with XSLT in Umbraco

  1. Iterating the nodes in umbraco.config file
  2. Filtering the nodes in umbraco.config file
  3. Working with umbraco xslt extension functions

Iterating the nodes in umbraco.config file

 

"currentPage” is the parameter in the template. The value is supplied by umbraco system when the template is invoked by umbraco system. It represents the current node where the xslt macro exists.

Let’s say, we have the content  structure in the screenshot above. If we put the xslt in the template of NewsPage, $currentPage represents the “NewsPage” node. So to iterate the child nodes in NewsPage, we will write the following code.

Note: “NewsItem” is the node name of the news.

Or

Please refer to “” section in w3school for more details for selecting nodes.

 

Filtering the nodes in umbraco.config file

You can use xpath predicates to filter the nodes.

Or

Please refer to “” section in w3school for more details for filtering nodes.

Working with umbraco xslt extension functions

Umbraco has shipped with rich set of xslt extension functions.

To apply the xslt extension functions, we must declare the xmlns for the xslt library.

Then invoke the functions as following.

We can create our own xslt extension functions to embrace specific business as well.

 

The skeleton of the article is completed. I will improve the content in the common tasks section in the coming up days.

Reference

 

 

Supported by

转载于:https://www.cnblogs.com/czy/archive/2012/07/23/2605770.html

你可能感兴趣的文章
一文读懂 JAVA 异常处理
查看>>
Js基础知识之----数据类型概述
查看>>
项目中常用的19条MySQL优化
查看>>
实现点击按钮后的CSS加载效果
查看>>
svg 线条动画浅尝
查看>>
LeetCode题库-深度优先搜索部分
查看>>
Java学习记录02
查看>>
Node.js是什么?
查看>>
Maven依赖冲突处理
查看>>
Python学习教程(Python学习路线):Python3你还未get到的隐藏技能
查看>>
258 Add Digits
查看>>
绘制 UIView 指定的边框
查看>>
nChain再获数字货币安全专利,助力BCH更加安全可靠
查看>>
关于content-Type看这偏文章就OK了
查看>>
HandleError过滤器
查看>>
Java标准库提取URL的域名
查看>>
SQL -- 简单语句学习总结7条
查看>>
Linux下安装php的memcache扩展库
查看>>
sgen.exe 已退出 代码为 1
查看>>
我的友情链接
查看>>