Subject: Re: [xsl] replace xml element From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Wed, 1 May 2002 09:47:25 +0100 |
Hi Valerie, > I have a question about replacing xml elements. Here is the problem; > I want to output the content of the element <content> and replace > the element <break/> with the html tag <br/>. I know this is > probably a very basic question but I appreciate your help. Rather than just getting the *value* of the content (with xsl:value-of), apply templates to it: <xsl:apply-templates select="item/par/content" /> and then add a template that matches break elements and, when they're encountered, inserts a br element to the result instead: <xsl:template match="break"> <br /> </xsl:template> When you tell the processor to apply templates to the content element, it will search through the templates in your stylesheet to find one that matches content elements. If it doesn't find one, it'll use the built-in template: <xsl:template match="*"> <xsl:apply-templates /> </xsl:template> This tells the processor to apply templates to all the child nodes of the matched (content) element -- the text nodes and the break elements. When the processor tries to find a template that matches text nodes, again it won't find one in your stylesheet, so it'll use the built-in one: <xsl:template match="text()"> <xsl:value-of select="." /> </xsl:template> so the value of each text node will be added to the result. When the processor tries to find a template that matches the break elements, it will find the one that you've provided, and add a br element to the result for each one. Applying templates to content and having templates to match different bits of that content (a push approach) is the best way of processing mixed content such as that in your example. 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] replace xml element, valerie liston | Thread | Re: [xsl] replace xml element, valerie liston |
[xsl] replace xml element, valerie liston | Date | [xsl] How can i access a JSP functi, Suman . Sathyanaraya |
Month |