View Single Post
  #2 (permalink)  
Old October 3rd, 2006, 01:38 PM
mhkay's Avatar
mhkay mhkay is offline
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Templates can only match nodes that exist, they can't match nodes that don't exist. You have to do the work in the template for the parent element (the one that knows it has a missing child). Generally in XSLT 1.0 there aren't any easy short cuts, you just need to write the conditional logic. There are some nice constructs in 2.0, like writing

<xsl:copy-of select="(a, $x)[1]"/>

which outputs a copy of a if it exists, or $x otherwise.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference