【发布时间】:2011-11-03 11:26:40
【问题描述】:
我必须使用 xslt 1.0 合并两个 xml 文档。每个 xml 文档都有一些文章,它们的标题和发布日期合二为一。条件是新xml文档中的文章要按日期升序排列。 以下是文档样本: doc1.xml 僵局移动 05-05/2002 一些文字 欧洲的反犹太主义 12-05/2002 还有一些文字
而doc2.xml文件是
<document>
<article>
<head>Launch Year A Success For Alliance</head>
<text>
<paragraph>para text</paragraph>
<paragraph>para text</paragraph>
<paragraph>para text</paragraph>
</text>
<date>
<day>17</day>
<month>05</month>
<year>2002</year>
</date>
<source>Alliance</source>
<portal>Finance</portal>
<ID number="27"/>
</article>
<article>
<head>ISA Savers Could Lose Tax Relief</head>
<text>
<paragraph>para text</paragraph>
<paragraph>para text</paragraph>
<paragraph>para text</paragraph>
<paragraph>para text</paragraph>
</text>
<date>
<day>10</day>
<month>05</month>
<year>2002</year>
</date>
<source>Money</source>
<portal>Finance</portal>
<ID number="26"/>
</article>
</document>
所需的输出是:
<document>
<article>
<head>The logjam moves</head>
<date>
<day>05</day>
<month>05</month>
<year>2002</year>
</date>
<text>Some text </text>
</article>
<article>
<head>ISA Savers Could Lose Tax Relief</head>
<text> para text para text para text para text </text>
<date>
<day>10</day>
<month>05</month>
<year>2002</year>
</date>
</article>
<article>
<head>Anti-Semitism in Europe</head>
<date>
<day>12</day>
<month>05</month>
<year>2002</year>
</date>
<text>some more text</text>
</article>
<article>
<head> Launch Year A Success For Alliance </head>
<text> para text para text para text para text </text>
<date>
<day>17</day>
<month>05</month>
<year>2002</year>
</date>
</article>
</document>
我的样式表是:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="doc1File">doc1.xml</xsl:param>
<xsl:variable name="doc1" select="document($doc1File)" as="document-node()"/>
<xsl:param name="doc2File">doc2.xml</xsl:param>
<xsl:variable name="doc2" select="document($doc2File)" as="document-node()"/>
<xsl:template match="/">
<xsl:for-each select ="$finance/document/article">
<xsl:value-of select="head"/>
<xsl:value-of select="text"/>
<xsl:value-of select="date"/>
</xsl:for-each>
<xsl:for-each select ="$economist/document/ARTICLE">
<xsl:value-of select="headline"/>
<xsl:value-of select="text"/>
<xsl:value-of select="date"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
如您所见,我只能打印元素的值。我无法弄清楚如何
- 解析 doc1.xml 中不同提及的日期和
- 合并两个文档,按发布日期排序
请帮忙。提前致谢。
【问题讨论】:
标签: xml sorting merge xslt-2.0