Question
· Jan 4

XSLT for FOP

Hi,

Im using an ORU_R01 2.3.1 message for converting to pdf. For the stylesheet, i need all the OBX segments under each OBR segment with  custom table headers. Can anyone help me with the xslt?

eg msg:
MSH|^~\&|WinPath|WinPath|EDT|TAY|202311262232||ORU^R01|49960|P|2.3.1|1||AL|||||
PID|||||TEST^CLINISYS||19740415|F||||||||||||||||||||||
PV1|||ZZZZ4^^^GP&GP^^^^^Virtual GP Practice||||||ZZZZ1^Dr Virtualone|E1||||||||NHS||||||||||||||||||||||||||||||||||
ORC|RE||23H00000055||CM||||202311131544||||||||||||NHS Tayside|||
OBR|1||23H00000055|HIST^HISTOLOGY^WinPath||202311131543|202311131045|||||||202311131544|APP&GI. Appendix|||||||202311131544||CP|F||||||||||||||||||||
OBX|1|FT|!AH^Assignments^WinPath||Histology\.br\    Primary: <None>||||||F||||||

OBX|1|FT|!AH^Assignments^WinPath||Histology\.br\    Primary: <None>||||||F||||||

OBR|1||23H00000055|jkjj^HISTOLOGY^WinPath||202311131543|202311131045|||||||202311131544|APP&GI. Appendix|||||||202311131544||CP|F||||||||||||||||||||
OBX|1|FT|!AH^Assignments^WinPath||Histology\.br\    Primary: <None>||||||F||||||

OBX|1|FT|!AH^Assignments^WinPath||Histology\.br\    Primary: <None>||||||F||||||

------------------------------My expected output is:

OBR1

Test

Flag

Result

Units

Ref Range

Comments

OBX1

 

4

U/L

5 - 55

 

OBX2 

 

2

umol/L

0 - 21

 

Alkaline phosphatase 

 

3

U/L

 

 

Albumin 

L

1

g/L

30 - 45

 

Calcium

H

5.00

mmol/L

2.10 - 2.55

 

Adjusted Calcium

 

 

 

 

Unable to calculate, Albumin < 16 mmol/L

 

OBR2

Test

Flag

Result

Units

Ref Range

Comments

obx1

 

147

g/L

 

 

obx2

 

10.0

10*9/L

4.0 – 11.0

 

obx3

 

150

10*9/L

150-400

 

RBC

 

25.00

10*12/L

 

 

Product version: Ensemble 2018.1
Discussion (1)1
Log in or sign up to continue

Hi,
can you try:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <!-- Match the root ORU_R01 message -->
  <xsl:template match="ORU_R01">
    <html>
      <body>
        <!-- Apply the transformation to each OBR segment -->
        <xsl:apply-templates select="//OBR"/>
      </body>
    </html>
  </xsl:template>

  <!-- Match each OBR segment -->
  <xsl:template match="OBR">
    <div>
      <!-- Output custom table header for OBR -->
      <h2>OBR Segment</h2>
      <table border="1">
        <tr>
          <th>Field 1</th>
          <th>Field 2</th>
          <!-- Add more headers as needed -->
        </tr>
        <tr>
          <!-- Output data for each field in the OBR segment -->
          <td><xsl:value-of select="OBR-1"/></td>
          <td><xsl:value-of select="OBR-2"/></td>
          <!-- Add more fields as needed -->
        </tr>
      </table>

      <!-- Apply the transformation to each OBX segment under the current OBR -->
      <xsl:apply-templates select="following-sibling::OBX[count(. | following-sibling::OBR[1]/preceding-sibling::OBX) = count(following-sibling::OBR[1]/preceding-sibling::OBX)]"/>
    </div>
  </xsl:template>

  <!-- Match each OBX segment under the current OBR -->
  <xsl:template match="OBX">
    <table border="1">
      <tr>
        <th>Custom Header 1</th>
        <th>Custom Header 2</th>
        <!-- Add more custom headers as needed -->
      </tr>
      <tr>
        <!-- Output data for each field in the OBX segment -->
        <td><xsl:value-of select="OBX-1"/></td>
        <td><xsl:value-of select="OBX-3"/></td> <!-- Adjust this line based on the actual field you want to display -->
        <!-- Add more fields as needed -->
      </tr>
    </table>
  </xsl:template>

</xsl:stylesheet>

Note that in the OBX template, I've used OBX-3 to display the data from the third field of each OBX segment. You should adjust this line based on the actual field you want to display in your PDF. If you have specific field names for OBX segments, replace them accordingly in the XSLT