Umbraco website creation (4) XSLT usage

Source: Internet
Author: User
Tags xsl xslt umbraco

XSLT extends the style sheet language. If you do not know, go to http://www.w3school.com.cn /.

In umbraco, XSLT is used a lot and has a lot of good effects, such as searching, specifying displayed entries, and so on.

In order to demonstrate this effectArticleWrite, we will create some more labels ,.

I have created another homepage tag.

It is worth noting that

Structure here, if we make a website, it must start from the home page. The home page can contain multiple subpages or other subpages.
Here, the homepage contains the hello subpage, which means that after creating the homepage, multiple Hello files can be contained in the homepage.

For example.

Home corresponds to my homepage template, while about and leave are my hello templates.

 

Next we select, developer, and enter an XSLT file in the new XSLT files key.

Check "create macro". A corresponding macro file is automatically created here.

.

Next, select the list. XSLT file. Here we can edit our XSLT file.

There are many things that can be written here. I will write an example showing the sub-page on the home page,CodeAs follows.

 

<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype XSL: stylesheet [<! Entity nbsp "">]>
<XSL: stylesheet
Version = "1.0"
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform"
Xmlns: MSXML = "urn: Schemas-Microsoft-com: XSLT"
Xmlns: umbraco. Library = "urn: umbraco. Library"
Exclude-result-prefixes = "MSXML umbraco. Library">

<XSL: output method = "XML" omit-XML-declaration = "yes"/>

<XSL: Param name = "currentpage"/>

<XSL: template match = "/">

<XSL: For-each select = "$ currentpage/ancestor-or-self: node [@ level = 1]/node [String (. /data [@ alias = 'umbraconavihide '])! = '1'] ">
<A href = "{umbraco. Library: niceurl (@ ID)}">
<XSL: attribute name = "title"> <XSL: value-of select = "@ nodename"/> </XSL: attribute>
<XSL: value-of select = "data [@ alias = 'pagehead']"/>
</A>
</XSL: For-each>

</XSL: Template>

</XSL: stylesheet>

 

Save. Then we go to the main template of the main template.

 

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">

<Head>
<Meta http-equiv = "content-language" content = "ZH-CN"/>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> heand </title>
<LINK rel = "stylesheet" type = "text/CSS" href = "/CSS/style.css" Media = "screen"/>

<SCRIPT src = "/scripts/BB. js" type = "text/JavaScript"> </SCRIPT>

</Head>

<Body>
<Div id = "content">
 <Div id = "heand"> <? Umbraco_macro macroalias = "list"> </? Umbraco_macro> </div>
<Div id = "Left"> </div>
<Div id = "right">
<? Umbraco_template_load_child/>
</Div>
</Div>
</Body>

</Html>

Note that this code references An XSLT written by me in the heand Div. The list name here is the macro file automatically created, the Macro file is specified to my list. XSLT

File. Save the settings.

Tip: The main template of the created homepage template is also selected.

Let's preview the effect ~!

As you can see, the above Div contains the titles of the two subpages that I did. Click to go to the corresponding content page. The navigation of such a website is ready ~!

Is it easy? If you have any questions, please contact us.

 

The main difficulty in writing this is in XSLT. If you are familiar with XPath, it will not be too difficult.

 

 

Obtain the top-level Directory: <XSL: For-each select = "$ currentpage/ancestor: Root/node">

Obtain the first and subdirectories: <XSL: For-each select = "$ currentpage/ancestor-or-self: node [@ level = 1]/node">

Obtain the second and sub-directories: <XSL: For-each select = "$ currentpage/ancestor-or-self: node [@ level = 2]/node">

Similarly ......

Sort: <XSL: Sort select = "@ updatedate" Order = "descending"/>

Link to the subpage: <a href = "{umbraco. library: niceurl (@ ID)} "> <XSL: value-of select =" @ nodename "/> </a>

 

Obtain sub-directories under this directory
<XSL: For-each select = "$ currentpage/node [String (data [@ alias = 'umbraconavihide '])! = '1'] ">

[String (data [@ alias = 'umbraconavihide '])! = '1'] indicates that the content is not displayed if umbraconavihide = 1. Indicates whether a file is hidden.

.

.

.

.

.

.

There are a lot more. Here is just a part. You can study it slowly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.