Assuming XSLT 2.0, here is some suggestion on how to approach that, assuming you really want some string output with quotes and plus symbols (to get Javascript or similar code to construct XML as a string?):
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="text"/>
<xsl:template match="*">
<xsl:param name="name" select="name()"/>
<xsl:text><</xsl:text>
<xsl:value-of select="$name"/>
<xsl:apply-templates select="@*"/>
<xsl:text>></xsl:text>
<xsl:apply-templates/>
<xsl:text></</xsl:text>
<xsl:value-of select="$name"/>
<xsl:text>></xsl:text>
</xsl:template>
<xsl:template match="@*">
<xsl:param name="name" select="name()"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$name"/>
<xsl:text>='</xsl:text>
<xsl:value-of select="."/>
<xsl:text>'</xsl:text>
</xsl:template>
<xsl:template match="text()[matches(., '^\s+$')]">
<xsl:text>"
+"</xsl:text>
</xsl:template>
<xsl:template match="/children">
<xsl:text>"</xsl:text>
<xsl:next-match>
<xsl:with-param name="name" select="'root'"/>
</xsl:next-match>
<xsl:text>"</xsl:text>
</xsl:template>
<xsl:template match="child">
<xsl:next-match>
<xsl:with-param name="name" select="'item'"/>
</xsl:next-match>
</xsl:template>
<xsl:template match="child//child">
<xsl:variable name="copy" as="element()">
<xsl:copy>
<xsl:attribute name="parent_id" select="ancestor::child[1]/@data"/>
<xsl:copy-of select="@* , node()"/>
</xsl:copy>
</xsl:variable>
<xsl:apply-templates select="$copy"/>
</xsl:template>
</xsl:stylesheet>
That transforms the input
<children>
<child data="test1">
<content><name>test1</name></content>
<child>
<content><name>test1child</name></content>
</child>
</child>
</children>
into the result
"<root>"
+"<item data='test1'>"
+"<content><name>test1</name></content>"
+"<item parent_id='test1'>"
+"<content><name>test1child</name></content>"
+"</item>"
+"</item>"
+"</root>"
The code so far has many shortcomings however as it would not construct well-formed XML with properly escaped attribute values and also does not care to output namespace declarations. You could however adapt more sophisticated solutions like http://lenzconsulting.com/xml-to-string/.
"and+characters to appear in the output as shown?<content>which are nowhere closed.