[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] xml fragment to string
I'm trying to find a way of converting an xml fragment into a string. The reason for wanting to do this is so that the fragment can be stored in an RDBMS as a string and I need to escape any apostrophes for the sql statement. My method that seems to work with the content that I have is to do the following: <xsl:variable name="xmlAsString" as="xs:string+"> <xsl:apply-templates> </xsl:variable> <!-- template to turn xml fragment into strings --> <xsl:template match="*"> <xsl:value-of select="concat('<', name())"/> <xsl:for-each select="@*"> <xsl:value-of select="concat(' ', name(), '="', .,'"')"/> </xsl:for-each> <xsl:value-of select="'>'"/> <xsl:value-of select="text()"/> <xsl:apply-templates select="*"/> <xsl:value-of select="concat('</', name(), '>')"/> </xsl:template> then to output the text (using replace() to escape apostrophes replace(string-join($xmlAsString, ''), '''', '''''') Are there are other better approaches? Is there a way of dealing with mixed content? Steven Hentschel
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|