我是胡萝卜新手,对xsl知之甚少,所以请多多包涵。我的输入文件是来自数据库的搜索结果的 xml。它不是胡萝卜格式,因此根据文档,我必须使用 xsl 文件将其转换为胡萝卜格式。我遵循了胡萝卜提供的示例 xsl(用于 bbc 新闻),但它没有找到我指定的标题(atl)、片段(ab)和链接(url)(得到返回消息“您的查询没有返回任何文档”) . 这是文件,如果有人可以提供帮助,我将不胜感激。太感谢了。
xml(我的 3 个示例搜索记录)
<?xml version="1.0" encoding="UTF-8"?>
<records>
<rec resultID="1">
<header shortDbName="aph" longDbName="Academic Search Premier" uiTerm="43811908">
<controlInfo>
<bkinfo />
<jinfo>
<jtl>BMC Public Health</jtl>
<issn>14712458</issn>
</jinfo>
<pubinfo>
<dt year="2007" month="01" day="01">2007</dt>
<vid>7</vid>
</pubinfo>
<artinfo>
<ppf>31</ppf>
<ppct>12</ppct>
<formats>
<fmt type="PDF" size="322KB" />
</formats>
<tig>
<atl>Cocaine- and opiate-related fatal overdose in New York City, 1990-2000.</atl>
</tig>
<aug />
<sug />
<pubtype>Academic Journal</pubtype>
<doctype>Article</doctype>
</artinfo>
<language code="eng">English</language>
</controlInfo>
<displayInfo>
<pLink>
<url>http://survey.hshsl.umaryland.edu/?url=http://search.ebscohost.com/login.aspx?direct=true&db=aph&AN=43811908&site=eds-live</url>
</pLink>
</displayInfo>
</header>
</rec>
<rec resultID="2">
<header shortDbName="aph" longDbName="Academic Search Premier" uiTerm="43830400">
<controlInfo>
<bkinfo />
<jinfo>
<jtl>BMC Public Health</jtl>
<issn>14712458</issn>
</jinfo>
<pubinfo>
<dt year="2007" month="01" day="01">2007</dt>
<vid>7</vid>
</pubinfo>
<artinfo>
<ppf>31</ppf>
<ppct>12</ppct>
<formats>
<fmt type="PDF" size="312KB" />
</formats>
<tig>
<atl>Cocaine- and opiate-related fatal overdose in New York City, 1990--2000.</atl>
</tig>
<aug />
<sug />
<pubtype>Academic Journal</pubtype>
<doctype>Article</doctype>
</artinfo>
<language code="eng">English</language>
</controlInfo>
<displayInfo>
<pLink>
<url>http://survey.hshsl.umaryland.edu/?url=http://search.ebscohost.com/login.aspx?direct=true&db=aph&AN=43830400&site=eds-live</url>
</pLink>
</displayInfo>
</header>
</rec>
<rec resultID="3">
<header shortDbName="cmedm" longDbName="MEDLINE" uiTerm="17334938">
<controlInfo>
<bkinfo />
<jinfo>
<jtl>Journal Of Urban Health: Bulletin Of The New York Academy Of Medicine</jtl>
<jtl>J Urban Health</jtl>
<issn type="Print">1099-3460</issn>
</jinfo>
<pubinfo>
<dt year="2007" month="03" day="01">2007 Mar</dt>
<vid>84</vid>
<iid>2</iid>
<place>United States</place>
</pubinfo>
<artinfo>
<ui type="pmid">17334938</ui>
<pages>292-306</pages>
<formats />
<tig>
<atl>Observed patterns of illicit opiate overdose deaths in Chicago, 1999-2003.</atl>
</tig>
<aug>
<au>Scott G</au>
<au>Thomas SD</au>
<aug>
<sug>
<subj type="geographic">Chicago</subj>
<subj type="major">Drug Overdose mortality</subj>
<subj type="major">Narcotics poisoning</subj>
<subj type="major">Opioid-Related Disorders mortality</subj>
<subj type="minor">Age Factors</subj>
<subj type="minor">Drug Overdose ethnology</subj>
<subj type="minor">Opioid-Related Disorders epidemiology</subj>
</sug>
<ab>This article explores trends and correlates of Chicago's opiate-related overdose (OD) deaths. We manually examined data from every death certificate filed between 1999 and 2003 to identify all Chicago residents' accidental deaths involving acute intoxication with illicit opiates, OD, or opiate poisoning.</ab>
<pubtype>Journal Article</pubtype>
</artinfo>
<language code="eng">English</language>
</controlInfo>
<displayInfo>
<pLink>
<url>http://survey.hshsl.umaryland.edu/?url=http://search.ebscohost.com/login.aspx?direct=true&db=cmedm&AN=17334938&site=eds-live</url>
</pLink>
</displayInfo>
</header>
</rec>
</records>
xsl(以下胡萝卜样本):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" omit-xml-declaration="no"
media-type="application/xml" encoding="UTF-8" />
<xsl:template match="/">
<searchresult>
<xsl:apply-templates select="/reords/rec/header" />
</searchresult>
</xsl:template>
<xsl:template match="header">
<document>
<title><xsl:value-of select="atl" /></title>
<snippet>
<xsl:value-of select="ab" />
</snippet>
<url><xsl:value-of select="url" /></url>
</document>
</xsl:template>
</xsl:stylesheet>