2012-03-20 27 views
-2

我正在使用xslt。我輸入文件將xslt應用於xml內容

<table bnf_id="bnf_204272" colsep="1" frame="all" id="nzf_3865" otherprops="HRT Risk table" pgwide="1" rowsep="1"><title>HRT Risk</title><tgroup cols="8" colsep="1" rowsep="1"><colspec colname="col1" /><colspec colname="col2" /><thead><row><entry morerows="1" rowsep="1">Risk</entry><entry morerows="1" rowsep="1">Age range (years)</entry><entry colsep="1" nameend="col4" namest="col3" rowsep="1">Background incidence per 1000 women in Europe not using HRT</entry><entry colsep="1" nameend="col6" namest="col5" rowsep="1"><b>Additional</b> 
        cases per 1000 women using 
        <b>oestrogen only HRT</b> 
        (estimated) 
       </entry><entry colsep="1" nameend="col8" namest="col7" rowsep="1"><b>Additional</b> 
        cases per 1000 women using 
        <b>combined (oestrogen-progestogen) HRT</b> 
        (estimated) 
       </entry></row><row><entry>Over 5 years</entry><entry nameend="col8" namest="col1"><b>Note</b><p>Where background incidence or additional cases have not been included in the table, this indicates a lack of available data. NS indicates a non-significant difference</p><p> 
        Taken from MHRA/CHM (<i>Drug Safety Update</i> 
        2007; 
        <b>1</b> 
        (2): 2–6) available at 
        <xref format="html" href="http://www.mhra.gov.uk/drugsafetyupdate"> 
         www.mhra.gov.uk/drugsafetyupdate 
        </xref></p></entry></row></tbody></tgroup></table> 

我的XSLT是

<xsl:template match="tgroup"> 
<tr> 

    <xsl:if test="@cols"> 
     <xsl:attribute name="cols"> 
     <xsl:value-of select="@cols"/> 
     </xsl:attribute> 
    </xsl:if> 

    <xsl:if test="@colsep"> 
     <xsl:attribute name="colsep"> 
     <xsl:value-of select="@colsep"/> 
     </xsl:attribute> 
    </xsl:if> 
    <xsl:if test="@rowsep"> 
     <xsl:attribute name="rowsep"> 
     <xsl:value-of select="@rowsep"/> 
     </xsl:attribute> 
    </xsl:if> 
    <xsl:if test="@align"> 
     <xsl:attribute name="align"> 
     <xsl:value-of select="@align"/> 
     </xsl:attribute> 
    </xsl:if> 
    <xsl:for-each select="colspec"> 
     <th> 
     <xsl:if test="@colwidth"> 
      <xsl:attribute name="width"> 
      <xsl:value-of select="@colwidth"/> 
      </xsl:attribute> 
     </xsl:if> 
     <xsl:if test="@colname"> 
      <xsl:attribute name="colname"> 
      <xsl:value-of select="@colname"/> 
      </xsl:attribute> 
     </xsl:if> 
     <xsl:if test="@align"> 
      <xsl:attribute name="align"> 
      <xsl:value-of select="@align"/> 
      </xsl:attribute> 
     </xsl:if> 
     <xsl:if test="@colsep"> 
      <xsl:attribute name="colsep"> 
      <xsl:value-of select="@colsep"/> 
      </xsl:attribute> 
     </xsl:if> 
     <xsl:if test="@colnum"> 
      <xsl:attribute name="colnum"> 
      <xsl:value-of select="@colnum"/> 
      </xsl:attribute> 
     </xsl:if> 

     </th> 
    </xsl:for-each> 


</tr> 
<xsl:apply-templates/> 

但具有相同的XSLT文件上面的代碼,我對日的第二場比賽被執行。 所以我得到空個像

<th></th> 

但我需要插入標記之間的...。如何解決它?

+1

此外,請給您輸入XML,如果沒有它,很難回答您的問題。 – ColinE 2012-03-20 06:14:59

+0

除了源XML文檔之外,請提供確切的通緝結果並解釋轉換必須實施的規則。 – 2012-03-20 13:40:52

+0

感謝您的建議。我添加了我的輸入文件,我不能放置我的整個xslt。所以我放置了xslt文件的一部分。 – Pooja 2012-03-21 03:45:47

回答

1

難道你不能簡單地加入以下內容xsl:如果條件前關閉</th >標籤?

<xsl:if test="@colnum"> 
     <xsl:attribute name="colnum"> 
      <xsl:value-of select="@colnum"/> 
     </xsl:attribute> 
    </xsl:if> 

    <xsl:if test="text() = ''"> 
     <xsl:text>...</xsl:text> 
    </xsl:if> 
</th>