Debugging custom transformations consists of a set of tools and techniques that can be applied to a variety of situations.
Debugging Code
<DEBUGGING> tags are a way to perform a step-by-step walkthrough of the transformation. Place the tags in the transformation at the location where you would like to capture a value. The code within the tags can capture the value of a variable, attribute, or XPath.
The following are examples of debugging code for different situations.
—Capturing the value of a variable—
Capturing the value of a variable
This example captures the value of a variable, $variable, within an XSL called FileName.xsl:
<DEBUGGING-VARIABLE-file-FileName.xsl-TemplateName>
$variable = <xsl:value-of select="$variable"/>
</DEBUGGING-VARIABLE-file-FileName.xsl-TemplateName>
—Capturing the value of an attribute—
Capturing the value of an attribute
This example captures an XSL path value of the root attribute located in /ClinicalDocument/id:
<DEBUGGING-PATHVALUE>
CDA source OID = <xsl:value-of select="/hl7:ClinicalDocument/hl7:id/@root"/>
</DEBUGGING-PATHVALUE>
—Capturing an XPath with Node Positions—
Capturing an XPath with Node Positions
Capturing an XPath takes advantage of templates. Calling the template currentXPathWithPos returns the current XPath with node positions, with ClinicalDocument/component[1] indicating, for example, the first component element inside ClinicalDocument. The following shows how to capture the XPath of the current position with node positions.
<DEBUGGING-PATHXMLWithPos>
<xsl:apply-templates select="." mode="currentXPathWithPos"/>
</DEBUGGING-PATHXMLWithPos>
The result of this call may be:
<DEBUGGING-PATHXMLWithPos>/ClinicalDocument[1]/component[1]/structuredBody[1]/component[8]
/section[1]/entry[1]/procedure[1]</DEBUGGING-PATHXMLWithPos>
—Capturing an XPath without Node Positions—
Capturing an XPath without Node Positions
Calling the currentXPath template returns the XPath without the node positions. The following example shows how to capture the XPath of the current position without node positions.
<DEBUGGING-PATHXMLWithoutPos>
<xsl:apply-templates select="." mode="currentXPath"/>
</DEBUGGING-PATHXMLWithoutPos>
The result of this call may be:
<DEBUGGING-PATHXMLWithoutPos>/ClinicalDocument/component/structuredBody/component
/section/entry/procedure</DEBUGGING-PATHXMLWithoutPos>
The templates currentXPathWithPos and currentXPath are found in install-dir/csp/xslt/SDA3/CDA-Support-Files/System/Common/Functions.xsl.
—Capturing an XPath tree—
Calling the copy template returns the current XPath tree. The following example captures the current XPath tree by inserting the current XPath tree in a DEBUGGING tag:
<DEBUGGING-PATHXMLTree>
<xsl:apply-templates select="." mode="copy"/>
</DEBUGGING-PATHXMLTree>
The template copy is found in install-dir/csp/xslt/SDA3/CDA-Support-Files/System/Common/Functions.xsl
These <DEBUGGING> tags and the values they capture are displayed in the transformations, but they are not displayed in places such as the Clinical Viewer and the View Summary page.
<DEBUGGING> tags may short-circuit CDA processing. Accordingly, they should be used during the debugging process only.