I haven't analysed your code fully but, at first glance, there are two errors:
* You call a template named "field" but there isn't one with that name. There is one that matches "field". You either need to apply-templates and select "field" or remove the match attribute on the template and name it "field".
* You try to use a variable holding a string value as an XPath expression. $xpath_node_TPXML is a string and just because what it holds is a string representation of XPath doesn't mean you can interchange them. If you need to do that then you can either use an extension function, Saxon for instance has the saxon:evaluate function or it's easy enough to write your own in JScript or C# if using a Microsoft processor. Alternatively you can perform two transformations, one to create a new XSLT that has the XPaths retrieved from SQL_XML embedded in the transform. For example create a number of variables such as: xsl:variable name="field1" select="//field[@name='TP_field1']". Then run this transform against the source document.
--
Joe (
Microsoft MVP - XML)