Subject: Re: [xsl] Newbie Question From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 17 May 2002 10:33:45 +0100 |
Hi Roger, > I really thought I was getting the hang of XSLT, until this. I know > what's happening, the "catchall" template is outputting the value of > the elements it see's. What I don't understand is why? You're running foul of the built-in templates in XSLT, specifically the one that looks like: <xsl:template match="text()"> <xsl:value-of select="." /> </xsl:template> This template means that unless you have an overriding template, whenever you apply templates to a text node, you get the value of that text node. You're applying templates to the text nodes within most of your elements, because the template you have for most elements is: <xsl:template match="*"> <xsl:apply-templates/> </xsl:template> which is the same as: <xsl:template match="*"> <xsl:apply-templates select="node()" /> </xsl:template> and tells the processor to apply templates to all the child nodes of each element it finds. (By the way, there's a template just like this built-in to XSLT; if you left out this template, your stylesheet would behave in exactly the same way.) The best way to prevent the text nodes that you're not interested in from being shown is to not apply templates to them in the first place. You could change your template so that it only applies templates to child elements, as follows: <xsl:template match="*"> <xsl:apply-templates select="*" /> </xsl:template> Alternatively, you could override the built-in template for text nodes so that you don't emit anything when you find them: <xsl:template match="text()" /> The former solution is better -- it gives the processor less work to do because it doesn't have to figure out what template to apply to the text nodes, and it means that you don't have to worry about what happens when you *do* want to apply templates to text nodes directly. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Newbie Question, Varley, Roger | Thread | [xsl] Regular expressions in a sche, Chuck Paussa |
[xsl] Using regular expressions in , trang_nguyen | Date | Re: [xsl] basic xslt question, G. Ken Holman |
Month |