Q:

Printing the set of key-value pairs of data inside a XML element using XSLT

For a given XML Node I need to get the key value pairs of it.  For an example:
For XML :
<root>
    <detail1>
        <test1> Text1 </test1>
        <test2> Text2 </test2>
        <test3> Text3 </test3>
    </detail1>
    <detail2> description 1 </detail2>
    <detail3> description 2 </detail3>
</root>

I need a table as follows (Ignoring the top most element) :

detail1 | test1 : Text1 
        | test2 : Text2
        | test2 : Text3
        |
detail2 | description 1
        |
detail3 | description 2

Is this possible with XSLT?  If anyone can point me to a example or a resource it would be very useful. 

A:

This transformation:
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:strip-space elements="*"/>

 <xsl:variable name="vBlanks" select="'                         '"/>

 <xsl:template match="/*/*">
  <xsl:value-of select="concat('&#xA;', name(), ' | ')"/>
  <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match="/*/*/*">
  <xsl:value-of select="concat(name(), ' : ')"/>
  <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match="/*/*/*[not(position()=1)]">
  <xsl:text>&#xA;</xsl:text>
  <xsl:value-of select="substring($vBlanks,1,string-length(name(..))+1)"/>
  <xsl:value-of select="concat('| ', name(), ' : ')"/>
  <xsl:apply-templates/>
 </xsl:template>
</xsl:stylesheet>

when applied on the provided XML document:
<root>
    <detail1>
        <test1> Text1 </test1>
        <test2> Text2 </test2>
        <test3> Text3 </test3>
    </detail1>
    <detail2> description 1 </detail2>
    <detail3> description 2 </detail3>
</root>

produces the wanted, correct result:
detail1 | test1 :  Text1 
        | test2 :  Text2 
        | test3 :  Text3 
detail2 |  description 1 
detail3 |  description 2 

