Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] replace xml element

From: Jeni Tennison <jeni@---------------->
To:
Date: 5/1/2002 12:41:00 AM
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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent