2014-11-05 81 views
0

XML片斷如何爲這樣的代碼編寫xsl模板?

<para><place>Cape Town</place> Some 150 penguins unaffected by the oil spill began their long swim from Port Elizabeth in the Eastern Cape back to their breeding habitat at Robben Island near Cape Town on Wednesday.</para> 

XSLT

<xsl:template match="company"> 
<xsl:value-of select="text()"/> 
</xsl:template>  


<xsl:for-each select="para"> 
     <xsl:value-of select="text()"/> 
     <xsl:if test="place"> 
      <xsl:apply-templates select="place" /> 
     </xsl:if> 
</xsl:for-each> 

您好我一直在寫的.xsl文件.XML和我堆棧。當我運行此代碼時,我只看到 place元素中的代碼,其餘文本被忽略。你能給我一些提示嗎?

+0

您可以添加所需的輸出並放置更完整的XML嗎?例如。公司標籤丟失。 – Kokkie 2014-11-05 12:16:06

+0

它應該是地方而不是公司。 XML代碼位於頂部。從.xsl文件的代碼下面。 – user3607625 2014-11-05 12:22:33

回答

1

這可以幫助你:

<?xml version="1.0" encoding="ISO-8859-1"?> 

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

<xsl:template match="place"> 
    <xsl:value-of select="text()"/> 
</xsl:template> 

<xsl:template match="para"> 
    <xsl:value-of select="text()"/> 
    <xsl:apply-templates select="place" /> 
</xsl:template> 


</xsl:stylesheet> 

你的目標是沒說清楚,但上面的代碼應該給你的想法。我已經離開了公司部分,因爲你的例子不包括一個。

+0

它的工作原理!謝謝! – user3607625 2014-11-05 12:27:55