This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: replace xml element


valerie liston wrote:
> Thanks Jeni, I'll give that a try but also I was just wondering is there a
> possibility of doing some sort of search and replace in xslt, ie. search
> through the whole xml doc and replace any occurrence of the tag <break/>
> with <br/>?

XSLT doesn't operate on an XML document as a string, it operates on a node
tree (kind of like the one implied by the DOM). You don't have access to the
serialized markup, so the answer to your question is "no", if you're asking
what I think you're asking. However, the answer Jeni gave you was correct and
achieves what you want.

You can visit every node in the document, making a copy of it along the way.
When you are visiting an element named 'break', you can have it be processed
by a different template that creates an empty 'br' element.

The recursive visit-and-copy algorithm is called the 'identity transform' and 
is demonstrated in the XSLT spec in the section on copying (xsl:copy).
The template to add to that example is just like the one Jeni said:

<xsl:template match="break">
  <br/>
</xsl:template>

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]