0

I'm finding it hard to create the XSLT stylesheet from the following input and output files.

Input XML:

<DocumentManagement>
<Document>
    <DocUniqueID>MedTypeABC1234140204132332932CL</DocUniqueID>
    <PatientID>ABC1234</PatientID>
    <CreationDate>03 Feb 2014</CreationDate>
    <DocumentClass>Clinical Letters</DocumentClass>
    <MimeType>application/msword</MimeType>

    <MetaData>
        <FieldName>Original Document Creation Date</FieldName>
        <Value>03 Feb 2014</Value>
    </MetaData>

    <MetaData>
        <FieldName>Subject</FieldName>
        <Value>Neurology</Value>
    </MetaData>

    <MetaData>
        <FieldName>Description</FieldName>
        <Value>Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit</Value>
    </MetaData>

    <MetaData>
        <FieldName>Clinician</FieldName>
        <Value>Dr. Adam Smith</Value>
    </MetaData>
</Document>
</DocumentManagement>

Desired Output XML:

<DocumentSet>
    <Comments>Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit/Comments>
    <Author>
        <Person value="Dr. Adam Smith" />
        <Role>Clinician</Role>
        <Speciality>Neurology</Speciality>
    </Author>
    <PatientId id="ABC1234" />
    <Document umiqueId="MedTypeABC1234140204132332932CL" creationTime="03 Feb 2014" mimeType="application/msword">
        <ClassCode description="Clinical Letters" />
        <FormatCode value="WORD" description="application/msword" />
    </Document>
</DocumentSet>

I'm having particular difficulty with:

  • Comments should get value from the 3rd metadata group.
  • Specialty should get value from the 2nd metadata group.
  • Person and role elements should get their values from the 4th metadata group.

Can somebody please show me the correct XSLT stylesheet? Thanks in advance.

I can only come up with the XSLT below and could not, of course, get my complete desired output.

  <xsl:template match="DocumentManagement/Document">
    <DocumentSet>
      <Comments>
        <xsl:value-of select="don't know what to put here"/>
      </Comments>
      <Author>
        <Person value="don't know what to put here" />
        <Role><xsl:value-of select="don't know what to put here"/></Role>
        <Speciality><xsl:value-of select="don't know what to put here"/></Speciality>
      </Author>
      <PatientId id="{PatientID}" />
      <Document umiqueId="{DocUniqueID}" creationTime="{CreationDate}" mimeType="{MimeType}">       
        <ClassCode description="{DocumentClass}" />
        <FormatCode value="don't know how to put correct value based on mimetype" description="{MimeType}" />
      </Document>
    </DocumentSet>  
  </xsl:template>
1
  • 1
    What did you try? xsl example? Commented Feb 6, 2014 at 1:15

1 Answer 1

1

Please see the code below:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="DocumentManagement">
        <DocumentSet>
            <!-- 'MetaData[3]' means the third MetaData, and so forth and so on-->
            <comment><xsl:value-of select="Document/MetaData[3]/Value"/></comment>
            <Author>
                <Person value="{Document/MetaData[4]/Value}" />
                <Role><xsl:value-of select="Document/MetaData[4]/FieldName"/></Role>
                <Speciality><xsl:value-of select="Document/MetaData[2]/Value"/></Speciality>
            </Author>
            <PatientId id="{Document/PatientID}" />
            <Document umiqueId="{Document/DocUniqueID}" creationTime="{Document/CreationDate}" mimeType="{Document/MimeType}">
                <ClassCode description="{Document/DocumentClass}" />
                <xsl:element name="FormatCode">
                    <xsl:attribute name="value">
                        <xsl:choose>
                            <xsl:when test="substring-after(Document/MimeType, 'application/')='msword'">
                                <xsl:text>WORD</xsl:text>
                            </xsl:when>
                            <!-- set other conditions here -->
                        </xsl:choose>
                    </xsl:attribute>
                    <xsl:attribute name="description">
                        <xsl:value-of select="Document/MimeType"/>
                    </xsl:attribute>
                </xsl:element>
            </Document>
        </DocumentSet>
    </xsl:template>


</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.