RE: [xsl] Replace characters in a node and all of its descendents

Subject: RE: [xsl] Replace characters in a node and all of its descendents
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Tue, 30 Sep 2003 12:07:30 -0400
[ Sergiu Ignat]
> I need to generate an SQL "INSERT INTO" statement from an xml 
> document.
> One of the columns must hold the string representation of an 
> XML node with all of its descendents.

I take it that you mean the xml itself, angle brackets and all, rather
than just the concatenated character data?

> To insert this node as a string I must replace each single 
> quote with other two single quotes for conformance with SQL syntax.

The best thing would be to post process with sed, python, perl, awk,
etc.  If for some reason you cannot do that, how hard it would be
depends on whether there are any attributes.  

If there are no attributes, then you only have to change the single
quotes in element content.  With xslt 1.0, you would have to use the
processor's xxx:node-set extension to turn the copy-of result tree
fragment into a node set, which you could then process with a recursive
template - or fsxsl - there are examples on Dave Pawson's FAQ site.

If there are attributes, then things would be much harder, since if you
used escaped quotes withing a start tag, you would no longer have xml.
I think that you would have to walk the entire tree, producing escaped
text where there used to be markup, and then fixing up single quotes as
above.  That would be fairly unpleasant and probable require the use of
disable-output-escaping, which is not portable across all processors.

Post-processing would be much better!


Tom P

 XSL-List info and archive:

Current Thread