XSLT - how to put the original XML into transformation results in text output mode

advertisements

i am trying to create a transformation which output will be text but including original xml as well. Simply i got the xml message that should be transformed to SQL insert but in case of an SQL error i want to insert the original xml message to database as well.

The input is e.g.:

<message><tag name="foo">dummy</tag></message>

The result of the transformation should be then:

INSERT INTO table (column) VALUES ('dummy')
IF @@error <> 0
BEGIN
   INSERT INTO errMsgLog (message) VALUES ('<message><tag name="foo">dummy</tag></message>')
END

The problem is if i set the output in XSLT to 'text' there are no xml tags included (just the values). So is there any mixed output mode or attribute override?

Thanks for any help.


Before approaching this solution (don't know if through XSLT you can find some better solution), also consider the problems you will encounter with much more complex input and output.

Even if purists will reject this answer (and the question also), you can use "xml" output method to do a (very ugly) trickery:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
        <xsl:text disable-output-escaping="yes">INSERT INTO table (column) VALUES ('dummy')
IF @@error &lt;> 0
BEGIN
     INSERT INTO errMsgLog (message) VALUES ('</xsl:text>
        <xsl:copy-of select="."/><xsl:text>')
END</xsl:text>
    </xsl:template>

</xsl:stylesheet>

outputs:

INSERT INTO table (column) VALUES ('dummy')
IF @@error <> 0
BEGIN
     INSERT INTO errMsgLog (message) VALUES ('<message><tag name="foo">dummy</tag></message>')
END