October 20, 2018
Hot Topics:


  • November 20, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »

In my view, without XSL (XSL is basically like a stylesheet, except it has its own syntax) XML is not very practical. XSL allows you to extract the data of a tag and format it however you want.

Say you have an XML document that looks like this:

<person>    <name>Sam Huggill</name></person>

This is very simple, but with XSL you can extractthe value in-between the <name> and </name> tags and formatit. We extract the value of a tag using the <xsl:value-of> tag:


(Notice the closing />. This means that the tag does not need another </xsl:value-of> tag). Easy.

But what happens when we have a more complicated XML document:

 <people>    <person>        <name>Sam Huggill</name>        <email>sam@vbsquare.com</email>    </person>    <person>        <name>Yourname</name>        <email>youremail</email>    </person></people> 

For this we will have to set up a loop to write the data from both <person> tags. We loop using the <xsl:for-each> tag:

 <xsl:for-eachselect="people/person">    <xsl:value-of select="name"/>    <xsl:value-of select="email"/></xsl:for-each> 

Page 2 of 6

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date