March 5, 2021
Hot Topics:


  • 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

This article was originally published on November 20, 2002

Enterprise Development Update

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

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