codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:



Previous Page  Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 

Summary

We've covered a lot of ground in this chapter. We've looked at full stylesheets for the first time – XML documents whose primary markup language is XSLT. You've learned how to convert from the starting point of a simplified stylesheet into a full stylesheet, by adding an <xsl:stylesheet> document element and an <xsl:template> element to give a template for the root node.

 

You've seen how an XSLT processor sees an XML document, as a node tree, and learned how to make an XSLT processor give you the output you want by telling it to apply templates to a bunch of nodes and providing the templates that it should use with them. You've discovered how to create templates that match various types of nodes:

 

        The root node

        Text nodes

        All element nodes

        Element nodes with particular names

        Element nodes with particular parents or ancestors

 

XSLT processors can only use one template to process a node when you apply templates to it. We've talked about how the processor deals with finding more than one template that matches a node by looking at the templates' priorities, and how it handles not finding one at all by using the built-in templates. You've also learned how to use modes to get the XSLT processor to use different templates in different situations.

 

Templates are the main constituent of a stylesheet, and the templates that you produce and the way you fit them together has a big effect on the stylesheet. You've now experienced the two main approaches used in stylesheets – push and pull – and we discussed the advantages and disadvantages of using each of them.


 

The XSLT that you've learned in this chapter hasn't much changed what you can generate from a stylesheet, just the way in which you get it. In the next chapter, we'll start looking at how to get a stylesheet to do more complicated processing dependent on the values of elements and attributes.

Review Questions

1.       Turn the following simplified stylesheet into a full stylesheet:

<?xml version="1.0" encoding="ISO-8859-1"?>

<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

      xsl:version="1.0">

  <head><title>Films</title></head>

  <body>

    <ul>

      <xsl:for-each select="/Films/Film">

        <li><xsl:value-of select="Name" /></li>

      </xsl:for-each>

    </ul>

  </body>

</html>

 

2.       What is the term for the node at the top of the node tree? What relationship does it have to the document element?

3.       Draw a node tree for the following XML document:

<?xml version="1.0" encoding="ISO-8859-1"?>

<?xml-stylesheet type="text/xsl" href="Films.xsl"?>

<Films>

  <Film rating="12">

    <Name>Crouching Tiger Hidden Dragon</Name>

    <Notes>

      Directed by <Director>Ang Lee</Director>.

    </Notes>

  </Film>

</Films>

 

4.       Which template is the first template to be processed when you use a stylesheet with an
entire document?

5.       What kind of nodes does the following template process, and what does it do with them?

<xsl:template match="Description//Film">

  <a href="http://www.imdb.com/Find?for={.}">

    <xsl:value-of select="." />

  </a>

</xsl:template>


 

6.       What will be the result of applying the following stylesheet to a document:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"

                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 

<xsl:template match="/">

  <xsl:apply-templates />

</xsl:template>

 

</xsl:stylesheet>

 

7.       Which of the following templates will be applied to a <Film> element that's a child of a <Link> element that's a child of a <Description> element:

<xsl:template match="Description/Link/Film">...</xsl:template>

<xsl:template match="Film" priority="1">...</xsl:template>

<xsl:template match="Description//Film" priority="-1">...</xsl:template>

<xsl:template match="*">...</xsl:template>

<xsl:template match="Link/Film" mode="Description">...</xsl:template>

 

8.       Which of the templates given in the previous question will be applied to the <Film> element if it's selected with the instruction:

<xsl:apply-templates mode="Description" />

Previous Page  Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 




Click here to Buy!

Buy Beginning XSLT here

© Copyright 2002 Wrox Press This chapter is written by Jeni Tennison and taken from "Beginning XSLT" published by Wrox Press Limited in June 2002; ISBN 1861005946; copyright © Wrox Press Limited 2002; all rights reserved.

No part of these chapters may be reproduced, stored in a retrieval system or transmitted in any form or by any means -- electronic, electrostatic, mechanical, photocopying, recording or otherwise -- without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews.











Recent Forum Threads
• C++
• Re: refresh parent after closing pop up window
• Dynamic Insertion
• Date and Time function around the world???
• Significant Factors
• Perl array access
• Re: huffman encoding and decoding in C++...
• Perl One Liner: Replace {(
• Re: html including php, accessing the functions


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009