ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: Creating empty elements
Submitter: Paul Prescod (other recipes)
Last Updated: 2001/06/27
Version no: 1.1
Category: Using HTML

 

2 stars 2 vote(s)


Approved

Description:

New XSLT users often have problems creating empty elements like <link>, <br>, <hr> and so forth in XSLT stylesheets. This recipe shows how.

Source: Text Source

<xsl:template match="/">
   <html>
   <title>Demonstrate line breaking</title>
   <p>This is a paragraph with a line break,<br/> in it.</p>
   Horizontal rule:<hr/>
   </html>
</xsl:template>

The license for this recipe is available here.

Discussion:

The "secret" is that you have to use XML syntax in the XSLT stylesheet even though the final output will be in HTML syntax. The XSLT stylesheet must be a well-formed document! But your XSLT implementation should do the "right thing" when it sees that the top-most element is an HTML element.



Add comment

Number of comments: 1

Annotation for the discussion, Robert Zimmermann, 2002/01/17
There is no need for magic in html output by the xslt-processor.
as xslt knows the output-element with wich the output format is defined:

<xsl:output method="html" .../>

Robert
Add comment



Highest rated recipes:

1. Search and Replace

2. Generating a newline

3. Internationalization ...

4. Restricting processing ...

5. Result Pagination with ...

6. Fetching information ...

7. Getting text children of ...

8. Creating empty elements




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.