Click to return to the XML (Extensible Markup Language) home page    
Debugging a Style Sheet     Scoping Templates     Advanced XSL Features    
Web Workshop  |  XML (Extensible Markup Language)

Simulating Built-in Templates


The December 1998 XSL Working Draft includes two built-in templates. These templates make it easier to create style sheets for irregular data by passing text from the source document to the output automatically.

Microsoft® Internet Explorer 5 does not have these templates built in but they are easily added to a style sheet without affecting the use of the style sheet by other XSL processors. Other processors will simply use the templates you specify instead of their own built-in templates.

The built-in templates in the XSL Working Draft look like this:

<xsl:template match="/|*"><xsl:apply-templates/></xsl:template>
<xsl:template match="text()"><xsl:value-of select="."/></xsl:template>

Place these templates at the start of the style sheet (before any other templates), otherwise they might prevent XSL from choosing the other templates in your style sheet.

On their own, these templates provide for a complete (albeit simple) transformation of the source document. Elements and the document root are traversed, although they do not generate any output themselves. The values of text nodes and CDATA sections are passed through. Comments and processing instructions are not processed and thus do not appear in the output. The end result is that these templates by themselves strip all markup from the source document but preserve the text.

Try it! You can see these templates in action in the XSL Working Draft Sample.

Download Download this sample.



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.