使用变量/未知值XSLT计数

时间:2017-11-29 04:54:33

标签: xml csv xslt foreach count

我是XSLT的新手,我正在尝试创建每个教授每年都有的出版物数量的CSV,每个条目都是一个不同的出版物,用  angular.module('test', []) .directive('statTable', statTable) .controller('statTableController', statTableController) .directive('testDirective', testDirective) .controller('testDirectiveController', testDirectiveController); function statTable() { return { scope: { scopeObj: "<" }, bindToController: true, controller: "statTableController", controllerAs: "vm", template: "<button class='btn-default' ng-click='vm.scopeObj.search1(\"search1\")'>Button1</button> <button class=\"btn-default\" ng-click=\"vm.scopeObj.search2('search2')\">Button2</button> <button class=\"btn-default\" ng-click=\"vm.scopeObj.search3('search3')\">Button3</button>" }; } function statTableController() { var vm = this; vm.log = console.log; } function testDirective() { return { controller: "testDirectiveController", controllerAs: "vm", template: "<stat-table scope-obj='::vm'></stat-table>" } } function testDirectiveController() { var vm = this; vm.search1 = function(val) { console.log("search1::", val); }; vm.search2 = function(val) { console.log("search2::", val); }; vm.search3 = function(val) { console.log("search3::", val); }; } 并且每年用dm:INTELLCONT表示如果我今年没有硬编码,我无法确定如何正确地执行此操作,我希望每年都能循环执行此操作&#39}发表了一些东西。我的当前XML文件是:

&#13;
&#13;
dm:DTY_PUB
&#13;
&#13;
&#13;

我当前的XSL文件是:

&#13;
&#13;
<?xml version="1.0" encoding="UTF-8"?>
<Data xmlns="http://www.digitalmeasures.com/schema/data" xmlns:dmd="http://www.digitalmeasures.com/schema/data-metadata" dmd:date="2017-10-16">
    <INTELLCONT id="151370213376" dmd:originalSource="MANAGE_DATA" dmd:lastModified="2017-10-03T11:41:47" dmd:startDate="2016-04-15" dmd:endDate="2016-04-15">
        <REFEREED>Yes</REFEREED>
        <CONTYPE>Abstract</CONTYPE>
        <CONTYPEOTHER/>
        <STATUS>Published</STATUS>
        <TITLE>Sample Title</TITLE>
        <TITLE_SECONDARY/>
        <DTM_PUB>April (2nd Quarter/Spring)</DTM_PUB>
        <DTD_PUB>15</DTD_PUB>
        <DTY_PUB>2016</DTY_PUB>
        <PUB_START>2016-04-15</PUB_START>
        <PUB_END>2016-04-15</PUB_END>
   <USER_REFERENCE_CREATOR>Yes</USER_REFERENCE_CREATOR>
    </INTELLCONT>
        <INTELLCONT id="151368284160" dmd:originalSource="MANAGE_DATA" dmd:lastModified="2017-10-03T10:44:48" dmd:startDate="2017-01-01" dmd:endDate="2017-12-31">
            <REFEREED>Yes</REFEREED>
            <CONTYPE>Journal Article</CONTYPE>
            <CONTYPEOTHER/>
            <STATUS>Published</STATUS>
            <TITLE>Sample Title</TITLE>
            <TITLE_SECONDARY/>
            <INTELLCONT_AUTH id="151368284163">
                <FACULTY_NAME/>
                <FNAME>FN</FNAME>
                <MNAME/>
                <LNAME>LN</LNAME>
                <INSTITUTION/>
                <ROLE>Author</ROLE>
                <STUDENT_LEVEL/>
            </INTELLCONT_AUTH>
            <INTELLCONT_AUTH id="151368284161">
                <FACULTY_NAME>1898739</FACULTY_NAME>
                <FNAME>FN</FNAME>
                <MNAME>MN</MNAME>
                <LNAME>LN</LNAME>
                <INSTITUTION/>
                <ROLE>Author</ROLE>
                <STUDENT_LEVEL/>
            </INTELLCONT_AUTH>
            <PUBLISHER>Public Health</PUBLISHER>
            <PUBCTYST/>
            <PUBCNTRY/>
            <VOLUME>14</VOLUME>
            <ISSUE>3</ISSUE>
            <PAGENUM>265</PAGENUM>
            <DTY_PUB>2017</DTY_PUB>
            <PUB_START>2017-01-01</PUB_START>
            <PUB_END>2017-12-31</PUB_END>
    <USER_REFERENCE_CREATOR>Yes</USER_REFERENCE_CREATOR>
        </INTELLCONT>
         <INTELLCONT id="151368284160" dmd:originalSource="MANAGE_DATA" dmd:lastModified="2017-10-03T10:44:48" dmd:startDate="2017-01-01" dmd:endDate="2017-12-31">
            <REFEREED>Yes</REFEREED>
            <CONTYPE>Journal Article</CONTYPE>
            <CONTYPEOTHER/>
            <STATUS>Published</STATUS>
            <TITLE>Sample Title</TITLE>
            <TITLE_SECONDARY/>
            <INTELLCONT_AUTH id="151368284163">
                <FACULTY_NAME/>
                <FNAME>FN</FNAME>
                <MNAME/>
                <LNAME>LN</LNAME>
                <INSTITUTION/>
                <ROLE>Author</ROLE>
                <STUDENT_LEVEL/>
            </INTELLCONT_AUTH>
            <PUBLISHER>Public Health</PUBLISHER>
            <PUBCTYST/>
            <PUBCNTRY/>
            <VOLUME>14</VOLUME>
            <ISSUE>3</ISSUE>
            <PAGENUM>265</PAGENUM>
            <DTY_PUB>2017</DTY_PUB>
            <PUB_START>2017-01-01</PUB_START>
            <PUB_END>2017-12-31</PUB_END>
            <USER_REFERENCE_CREATOR>Yes</USER_REFERENCE_CREATOR>
        </INTELLCONT>
</Data>
&#13;
&#13;
&#13;

正如您所看到的那样,我每年试图计算每个出版物的部分都有评论每年制表出版的论文

我希望每年发布一次并计算当年有多少出版物,任何帮助都会非常感谢,提前感谢!

1 个答案:

答案 0 :(得分:0)

你似乎已经掌握了XSLT 1.0 Muenchian Grouping的基本思想,这是很难的部分,然后你就在一个简单的上下文问题上滑倒了。这里:

<xsl:for-each select="dm:Record/dm:INTELLCONT[...]">
    <xsl:sort select="(dm:DTY_PUB)" order="ascending"/> 
    <xsl:value-of select="count(dm:Record/dm:INTELLCONT[..]/>
</xsl:for-each>

这是没有意义的,因为在for-each中,上下文项是一个INTELLICONT元素,你试图向下选择一个dn:RECORD。

在Muenchian分组中,您想要计算组的大小,逻辑结构是

<xsl:for-each select="one item with each key value">
  <xsl:value-of select="count(all items with the same key value)"/>
</xsl:for-each>

所以我希望看到count(key(....))

您确定不能使用XSLT 2.0和xsl:for-each-group吗?它让生活变得如此简单......