我发现很难从以下输入和输出文件创建XSLT样式表。
输入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>
所需的输出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>
我遇到了特别困难:
有人可以告诉我正确的XSLT样式表吗?提前谢谢。
我只能在下面提出XSLT,当然不能得到我想要的完整输出。
<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>
答案 0 :(得分:0)
请参阅以下代码:
<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>