我正在尝试编写一个xsl代码来查看日志名称,并且大多数情况下都是这样。我尝试搜索它,但无法理解其中的大部分(我是xslt新手)。有人能帮我吗?
我的XML(只有一个条目):
<Bibliography>
<row>
<Title>Title-B-0</Title>
<Author>Jason Adair</Author>
<Year>2015</Year>
<Publication_Name>ACM</Publication_Name>
<DOI>533/49</DOI>
<Date>6/2/2021</Date>
<Journal_Name>journal-s</Journal_Name>
<Journal_Volume>9</Journal_Volume>
<Journal_Issue>8</Journal_Issue>
<Conference_Name></Conference_Name>
<Conference_Location></Conference_Location>
<Book_Title></Book_Title>
<Book_Editor></Book_Editor>
</row>
</Bibliography>我的XSL方法:
<xsl:variable name="maximum">
<xsl:for-each select="//row">
<xsl:sort select="count(//row[@Journal_Name=current()/@Journal_Name])" order="descending" />
<xsl:if test="position() = 1">
<xsl:value-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:variable>
Most occuring value of journal is: <xsl:value-of select = "$maximum" />另外,在我正在看的一个YouTube教程中,这个家伙在浏览器中运行xml,它是自动的样式,但是当我这样做的时候,我不能。新浏览器不再支持xml和xsl了吗?
发布于 2021-03-30 15:02:19
这其实是一个分组问题。假设您使用的是XSLT1.0处理器,最好使用门窗分组法的变体。下面是一个简化的示例:
XML
<Bibliography>
<row>
<Journal_Name>journal-a</Journal_Name>
</row>
<row>
<Journal_Name>journal-b</Journal_Name>
</row>
<row>
<Journal_Name>journal-c</Journal_Name>
</row>
<row>
<Journal_Name>journal-b</Journal_Name>
</row>
<row>
<Journal_Name>journal-c</Journal_Name>
</row>
<row>
<Journal_Name>journal-d</Journal_Name>
</row>
<row>
<Journal_Name>journal-b</Journal_Name>
</row>
</Bibliography>XSLT1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="row-by-journal" match="row" use="Journal_Name" />
<xsl:template match="/Bibliography">
<output>
<!-- for each distinct journal name -->
<xsl:for-each select="row[count(. | key('row-by-journal', Journal_Name)[1]) = 1]">
<!-- sort by group size -->
<xsl:sort select="count(key('row-by-journal', Journal_Name))" data-type="number" order="descending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="Journal_Name" />
</xsl:if>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>结果
<?xml version="1.0" encoding="UTF-8"?>
<output>journal-b</output>请注意,如果使用tie,此方法将只返回一个顶级值。
https://stackoverflow.com/questions/66872436
复制相似问题