如何为下面的xml生成xslt?

时间:2015-10-21 22:37:56

标签: xslt

我正在创建一个创建XML的应用程序,如下所示:

<Section ExcludedFromGPCopy="false" ExcludedFromPatientCopy="false" Name="Medications" PrintSectionTitle="true" RichText="false" Title="Medications">
    <TextObservation>
        <TextType>MedChartInpatientMedications</TextType>
        <TextValue>
Frusemide 40mg -Tablet - Oral - 40 mg - [In the Morning (08:00) every day]&#xd;   
Prednisolone 5mg -Tablet - Oral - 10 mg - [In the Morning (08:00) on Alternate Days]&#xd;  
Warfarin -Tablet - Oral - Dose varies depending on INR - [Every 1 day as per INR  for Pulmonary embolus]&#xd;  
Thyroxine 50mcg -Tablet - Oral - 50 mcg - [In the Morning (08:00) on even days of the month]&#xd;  
Sennosides 12mg -Chewable Tablet - Oral - 12 mg - [In the Morning (08:00) every day]&#xd;  
Cephazolin 1g -Injection - Intravenous - 2 g - [Four Times Daily (06:00, 12:00, 18:00, 22:00) every day for 1 week]&#xd;   
</TextValue>

我的XSLT如下:

MedChart Inpatient Medications          
<fo:table table-layout="fixed" keep-together.within-column="always">                                                        
        <fo:table-column column-width="110pt" />
        <fo:table-column column-width="110pt" />
        <fo:table-column column-width="110pt" />
        <fo:table-column column-width="110pt" />
        <fo:table-column column-width="73pt" />
        <fo:table-body font-family="sans-serif" font-size="9pt">                
                <fo:table-row keep-with-next="always">
                        <fo:table-cell border-width="0.5pt" border-bottom-width="1pt" border-style="solid" padding="2pt">
                            <fo:block text-align="center" font-weight="bold" padding="2px"> Description
                                <xsl:analyze-string select="TextValue" regex="^(.*)\s*\-\s*(.*)\s*\-\s*(.*)\s*\-\s*(.*)\s*\-\s*\[(.*)\].*"> 
                                    <xsl:matching-substring>    
                                        <xsl:value-of select="xsl:regex-group(1)"/>                                                         
                                    </xsl:matching-substring>
                                    <xsl:non-matching-substring> 
                                       <xsl:value-of select="." /> 
                                    </xsl:non-matching-substring>
                                 </xsl:analyze-string>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell border-width="0.5pt" border-bottom-width="1pt" border-style="solid" padding="2pt">
                            <fo:block text-align="center" font-weight="bold" padding="2px"> Form
                                <xsl:analyze-string select="TextValue" regex="^(.*)\s*\-\s*(.*)\s*\-\s*(.*)\s*\-\s*(.*)\s*\-\s*\[(.*)\].*"> 
                                    <xsl:matching-substring>    
                                        <xsl:value-of select="xsl:regex-group(1)"/>                                                         
                                    </xsl:matching-substring>
                                    <xsl:non-matching-substring> 
                                       <xsl:value-of select="." /> 
                                    </xsl:non-matching-substring>
                                 </xsl:analyze-string>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell border-width="0.5pt" border-bottom-width="1pt" border-style="solid" padding="2pt">
                            <fo:block text-align="center" font-weight="bold" padding="2px"> Route
                                <xsl:analyze-string select="TextValue" regex="^(.*)\s*\-\s*(.*)\s*\-\s*(.*)\s*\-\s*(.*)\s*\-\s*\[(.*)\].*"> 
                                    <xsl:matching-substring>    
                                        <xsl:value-of select="xsl:regex-group(1)"/>                                                         
                                    </xsl:matching-substring>
                                    <xsl:non-matching-substring> 
                                       <xsl:value-of select="." /> 
                                    </xsl:non-matching-substring>
                                 </xsl:analyze-string>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell border-width="0.5pt" border-bottom-width="1pt" border-style="solid" padding="2pt">
                            <fo:block text-align="center" font-weight="bold" padding="2px"> Dosage
                                <xsl:analyze-string select="TextValue" regex="^(.*)\s*\-\s*(.*)\s*\-\s*(.*)\s*\-\s*(.*)\s*\-\s*\[(.*)\].*"> 
                                    <xsl:matching-substring>    
                                        <xsl:value-of select="xsl:regex-group(1)"/>                                                         
                                    </xsl:matching-substring>
                                    <xsl:non-matching-substring> 
                                       <xsl:value-of select="." /> 
                                    </xsl:non-matching-substring>
                                 </xsl:analyze-string>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell border-width="0.5pt" border-bottom-width="1pt" border-style="solid" padding="2pt">
                            <fo:block text-align="center" font-weight="bold" padding="2px"> Schedule
                                <xsl:analyze-string select="TextValue" regex="^(.*)\s*\-\s*(.*)\s*\-\s*(.*)\s*\-\s*(.*)\s*\-\s*\[(.*)\].*"> 
                                    <xsl:matching-substring>    
                                        <xsl:value-of select="xsl:regex-group(1)"/>                                                         
                                    </xsl:matching-substring>
                                    <xsl:non-matching-substring> 
                                       <xsl:value-of select="." /> 
                                    </xsl:non-matching-substring>
                                 </xsl:analyze-string>
                            </fo:block>
                        </fo:table-cell>
                </fo:table-row>                                                                                                                         
        </fo:table-body>
</fo:table>

<xsl:call-template name="tokenize"> 
    <xsl:with-param name="text" select="PrescriptionMessage/Section[@Title='MedChart Inpatient Medications']/TextObservation[TextType='MedChartInpatientMedications']/TextValue"/>  
    <xsl:with-param name="separator" select="'-'"/>  
</xsl:call-template>

<xsl:template name="tokenize">
    <xsl:param name="text"/>
    <xsl:param name="separator" /> 
    <xsl:param name="terminator" select="'&#xd;'"/> 
    <xsl:choose>

        <xsl:when test="not(contains($text, $terminator))">  
            <fo:block text-align="left" font-weight="normal" padding="2px"><xsl:value-of select="normalize-space($text)"/></fo:block>
        </xsl:when> 
        <xsl:otherwise>   

            <fo:block text-align="left" font-weight="normal" padding="2px"><xsl:value-of select="normalize-space(substring-before($text, $terminator))"/> </fo:block>     
            <xsl:call-template name="tokenize" >
                <xsl:with-param name="text" select="substring-after($text, $terminator)"/>
            </xsl:call-template>  
        </xsl:otherwise>
    </xsl:choose> 
</xsl:template>`

我希望我的输出在表格格式中如下所示。我正在尝试使用&#34; - &#34;分离XML内容(药物数据内容)。从每个文本段,并以表格格式。如何做到这一点,因为上面的xslt代码没有读取 analyze string tokenize 字符串。我正在使用xslt 1.0

Description       Form     Route    Dosage     Schedule

Frusemide 40mg    Tablet   Oral     40 mg      In the Morning (08:00) every day  
Prednisolone 5mg  Tablet   Oral     10 mg      In the Morning (08:00) on Alternate Days

0 个答案:

没有答案