我正在尝试使用XSLT阅读下面显示的xml文件。我只能读取文件的第一个内容,但不能读取文件的所有内容。请帮我解决问题。
XML:
<?xml version="1.0" encoding="UTF-8"?><records><record>
<Headline>ABC</Headline>
<News_details>Date: July 7 ABCDEFGHIJK</News_details>
</record>
<record>
<Headline>DEF</Headline>
<News_details>Date: July 9 ABCDXYZ</News_details>
</record>
<record>
<Headline>GHI</Headline>
<News_details>Date: July 11 QWERTYMNBV</News_details>
</record>
</records>
XSLT代码:
<xsl:template match="/">
<vse>
<document url="{$crawl-url-url}">
<content name="Headline">
<xsl:for-each select="//Headline" />
<xsl:value-of select="//Headline" />
</content>
<content name="News Details">
<xsl:for-each select="//News_details" />
<xsl:value-of select="//News_details" />
</content>
</document>
</vse>
</xsl:template>
我得到的输出是:
<document url="file:///C%3a%5cUsers%5cIBM_ADMIN%5cMy%20Documents%5cSametimeFileTransfers%5csamplenews.xml"><content name="Headline">ABC</content><content name="News Details">Date: July 7 ABCDEFGHIJK</content></document>
答案 0 :(得分:-1)
以下XSLT将为您提供所需的结果。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<xsl:template match="/">
<vse>
<document>
<xsl:for-each select="/*[local-name()='records']/*[local-name()='record']" >
<content name="Headline">
<xsl:value-of select="/*[local-name()='records']/*[local-name()='record']/*[local-name()='Headline']" />
</content>
<content name="News_details">
<xsl:value-of select="/*[local-name()='records']/*[local-name()='record']/*[local-name()='News_details']" />
</content>
</xsl:for-each>
</document>
</vse>
</xsl:template>
</xsl:stylesheet>