我有以下一段 XML:
<research>
<research.record>
<research.record_number>1</research.record_number>
<research.type>
<value lang="en-US">some research type</value>
</research.type>
<research.type>
<value lang="en-US">some other type of research</value>
</research.type>
<project.record>
<priref>101</priref>
<project.type>
<value lang="en-US">some type of project</value>
</project.type>
</project.record>
</research.record>
</research>
<research>
<research.record>
<research.record_number>2</research.record_number>
<research.type>
<value lang="en-US">some other type of research</value>
</research.type>
<research.type>
<value lang="en-US">a third type of research</value>
</research.type>
<project.record>
<priref>101</priref>
<project.type>
<value lang="en-US">some type of project</value>
</project.type>
</project.record>
</research.record>
</research>
<research>
<research.record>
<research.record_number>3</research.record_number>
<research.type>
<value lang="en-US">some other type of research</value>
</research.type>
<research.type>
<value lang="en-US">a fourth type</value>
</research.type>
<project.record>
<priref>201</priref>
<project.type>
<value lang="en-US">some other type of project</value>
</project.type>
</project.record>
</research.record>
</research>
<research>
... etc ...
在 XSLT 1.0 中,我使用 xsl:key 将此 XML 转换为唯一项目记录的列表。
到目前为止,一切都很好...
问题是:我还想为每个独特的项目记录显示独特的研究类型。
我的简化样式表显示了重复的研究类型(但不是唯一的)
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" indent="yes"/>
<xsl:key name="uniqueProject" match="project.record" use="priref"/>
<xsl:template match="record">
<div class="table-row">
<xsl:apply-templates select="//project.record[generate-id() = generate-id(key('uniqueProject', priref)[1])]">
<xsl:sort select="startdate"/>
</xsl:apply-templates>
</div>
</xsl:template>
<xsl:template match="project.record">
<div class="project-container">
<xsl:text>project.record </xsl:text>
<xsl:value-of select="priref"/>
<xsl:text>: </xsl:text>
<xsl:for-each select="//research/research.record/research.type[../project.record/priref = current()/priref]">
<xsl:sort select="value[@lang='en-US']" data-type="text" />
<xsl:if test="value[@lang='en-US'][not(.=preceding::research/research.record/research.type/value[@lang='en-US'][../../project.record/priref = current()/priref])]">
<xsl:value-of select="value[@lang='en-US']"/>
</xsl:if>
<xsl:if test="position()!=last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</div>
<br/>
<br/>
</xsl:template>
</xsl:stylesheet>
我想要的输出是:
project.record 101: some research type, some other type of research, a third type of research
project.record 201: some other type of research, a fourth type
希望有人可以帮助我使用正确的 XSLT/XPATH。(只能使用XSLT1.0)