Converting node to string with XSLT

If you simply write:

<xsl:value-of select="//some-element"/>  

you get just a string of it's internal text elements, no node names. It's naked.

If you write:

<xsl:copy-of select="//some-element"/>  

You get just the copy of everything.

You can convert an element to string in a following way:

<xsl:variable name="full-string">  
  <xsl:apply-templates select="//some-element" mode="serialize"/>
</xsl:variable>  

For that to work, define two new templates:

<xsl:template match="*" mode="serialize">  
  <xsl:text><</xsl:text><xsl:value-of select="name(.)"/>
  <xsl:text>></xsl:text>
  <xsl:apply-templates mode="serialize"/>
  <xsl:text></</xsl:text><xsl:value-of select="name(.)"/>
  <xsl:text>></xsl:text>
</xsl:template>

<xsl:template match="text()" mode="serialize">  
  <xsl:value-of select="."/>
</xsl:template>