2014-11-05 75 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