Subject: Re: [xsl] apply-templates and predicates From: David Carlisle <davidc@xxxxxxxxx> Date: Thu, 28 Apr 2005 10:45:05 +0100 |
It also increases the chances that the stylesheet will do something unwanted when the schema changes Not necessarily. As I've mentioned earlier in this thread I almost always start off with a template <xsl:template match="*"> <xsl:message>unexpected element ...</xsl:message> <xsl:template> when I think I have finished and added sufficient templates that <xsl:apply-templates/> generates no more warning messages, then if the input changes on me and new elements are added the stylesheet doesn't just silently accept the input, it starts warning again. This mechanism is flexible in that depending on the context it can be modified to make the warnings fatal errors, or no warnings at all, depending on circumstances. If on the other hand instead of <xsl:apply-templates/> I just have <xsl:apply-templates select="A|b[@foo]|C/> because that's the only type of element that I expect to see, and I only have templates for those elements, then if the schema changes and the input has new elements, they will be silently ignored. Similarly if instead of <xsl:apply-templates/> I just have <xsl:apply-templates select="*[not(self::F)]/> Because I believed that the only element type that I didn't need to handle was F, and I didn't want to write an empty template for F, then if the schema changes and a new element type appears this will be handled by the default template (whatever that does) without warning. It's not a clear cut choice: most stylesheets use both forms to some extent, but I think that it is definitely the case that in the face of under specified or changing input, keeping select attributes simple and putting more logic into the match templates is usually preferable. David ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] apply-templates and predi, tom tom | Thread | RE: [xsl] apply-templates and predi, Wendell Piez |
Re: [xsl] apply-templates and predi, tom tom | Date | Re: [xsl] apply-templates and predi, David Carlisle |
Month |