Summary of attributes in XSLT

Source: Internet
Author: User
Tags xsl xslt
The methods for accessing attributes are the same as those for accessing elements. Note that the attribute name is preceded by the "@" symbol.

XML source code<Source>

<Dog name = "Joe">
<Data Weight = "18 kg" color = "black"/>
</Dog>

</Source>

Output<P>
<B> dog: </B> Joe </P>
<P>
<B> color: </B> black </P>

View in HTML

Dog:Joe

Color:Black

XSLT stylesheet <XSL: stylesheet version = '1. 0'
Xmlns: XSL = 'HTTP: // www.w3.org/5o/#/transform'>

<XSL: template match = "dog">
< P >
< B >
<XSL: Text> dog: </XSL: Text>
</ B >
<XSL: value-of select = "@ name"/>
</ P >
< P >
<B >
<XSL: Text> color: </XSL: Text>
</ B >
<XSL: value-of select = "Data/@ color"/>
</ P >
</XSL: Template>

</XSL: stylesheet>

Attributes and elements are processed in the same way.

XSLT stylesheet 1
XML source code<Source>

<Employee ID = "js0034"> Joe Smith </employee>

</Source>

OutputJoe Smith
[<B>
<I> js0034 </I>
</B>]

View in HTMLJoe Smith [ Js0034 ]

XSLT stylesheet <XSL: stylesheet version = '1. 0'
Xmlns: XSL = 'HTTP: // www.w3.org/5o/#/transform'>

<XSL: template match = "employee">
<XSL: value-of select = "."/>
<XSL: Text> [</XSL: Text>
<XSL: Apply-templates select = "@ ID"/>
<XSL: Text>] </XSL: Text>
</XSL: Template>

<XSL: template match = "@ ID">
<B>
<I>
<XSL: value-of select = "."/>
</I>
</B>
</XSL: Template>

</XSL: stylesheet>

You can also select an element by checking whether it contains certain attribute values. XSLT stylesheet 1 is selected, while XSLT stylesheet 2 exclude elements that contain specific attributes.

XSLT stylesheet 1
XML Source Code



output

Car: a234

Car: a111

View in HTML

Car: a234

Car: a111

XSLT stylesheet xmlns: XSL = 'HTTP: // www.w3.org/5o/#/transform'>


P
Car:

P

XSLT stylesheet 2
XML Source Code



output

Car: a005

View with HTML

Car: a005

XSLT stylesheet xmlns: XSL = 'HTTP: // www.w3.org/5o/#/transform'>


P
Car:

P

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.