How to create XSLT stylesheet from input and output XML files -


i'm finding hard create xslt stylesheet following input , 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 value 3rd metadata group.
  • specialty should value 2nd metadata group.
  • person , role elements should values 4th metadata group.

can please show me correct xslt stylesheet? in advance.

i can come xslt below , not, of course, complete desired output.

  <xsl:template match="documentmanagement/document">     <documentset>       <comments>         <xsl:value-of select="don't know put here"/>       </comments>       <author>         <person value="don't know put here" />         <role><xsl:value-of select="don't know put here"/></role>         <speciality><xsl:value-of select="don't know put here"/></speciality>       </author>       <patientid id="{patientid}" />       <document umiqueid="{docuniqueid}" creationtime="{creationdate}" mimetype="{mimetype}">                <classcode description="{documentclass}" />         <formatcode value="don't know how put correct value based on mimetype" description="{mimetype}" />       </document>     </documentset>     </xsl:template> 

please see 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 third metadata, , forth , 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> 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -