Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt XSL 2.0:计算唯一值的总数_Xslt_Xpath_Syntax_Count_Siblings - Fatal编程技术网

Xslt XSL 2.0:计算唯一值的总数

Xslt XSL 2.0:计算唯一值的总数,xslt,xpath,syntax,count,siblings,Xslt,Xpath,Syntax,Count,Siblings,以下是我的xml: <?xml version='1.0' encoding='UTF-8'?> <wd:Report_Data xmlns:wd="urn:com.workday.report/CR-INT034-ADP-Garnishment_Disbursements_File-Outbound2"> <wd:Report_Entry> <wd:field>1111</wd:field> </wd:Repor

以下是我的xml:

<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data xmlns:wd="urn:com.workday.report/CR-INT034-ADP-Garnishment_Disbursements_File-Outbound2">
  <wd:Report_Entry>
    <wd:field>1111</wd:field>
  </wd:Report_Entry>
  <wd:Report_Entry>
    <wd:field>2222</wd:field>
  </wd:Report_Entry>
  <wd:Report_Entry>
    <wd:field>3333</wd:field>
  </wd:Report_Entry>
  <wd:Report_Entry>
    <wd:field>2222</wd:field>
  </wd:Report_Entry>
  <wd:Report_Entry>
    <wd:field>3333</wd:field>
  </wd:Report_Entry>
  <wd:Report_Entry>
    <wd:field>1111</wd:field>
  </wd:Report_Entry>
</wd:Report_Data>

1111
2222
3333
2222
3333
1111
以下是我正在使用的xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:wd="urn:com.workday.report/CR-INT034-ADP-Garnishment_Disbursements_File-Outbound2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="no" method="text" />

<xsl:key name="entry" match="wd:Report_Entry" use="wd:field" />

<xsl:template match="wd:Report_Data">
    <xsl:value-of select="count(wd:Report_Entry | wd:field[ generate-id() = generate-id(key('entry', wd:field))])"/>     
</xsl:template>

</xsl:stylesheet>

我试图计算唯一的值。在上面的例子中,答案应该是3,我得到6

我调整了最初给出的答案,使其在1.0中工作,但我不能使用1.0,我必须使用2.0。有没有办法让它在2.0中运行,或者我只是运气不好

任何帮助都将不胜感激

谢谢

Sarah

以下使用和获取
wd:Report\u条目的不同列表,然后使用


既然您使用的是XSLT2.0,就可以使用
distinct-values()

XSLT2.0

<xsl:stylesheet xmlns:wd="urn:com.workday.report/CR-INT034-ADP-Garnishment_Disbursements_File-Outbound2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">
    <xsl:strip-space elements="*"/>
    <xsl:output indent="no" method="text"/>

    <xsl:template match="/*">
        <xsl:value-of select="count(distinct-values(wd:Report_Entry))"/>
    </xsl:template>

</xsl:stylesheet>

我不得不对它进行一些修改以使其正常工作,但它现在正在工作。非常感谢。你太棒了!!!最终代码:
这在2.0中不起作用。你能看一下,看看你是否能找到一个在2.0中工作的解决方案吗。我已经编辑了我的问题以包含更好的xml和xslt。我错放了谓词筛选器(应用于
generate-id()
的结果,而不是从
key()返回的集合)
,在我测试时使用Saxon运行时,它正好工作。我已经更新了它以更正表达式,因此它应该在任何XSLT引擎中作为1.0或2.0样式表运行。太棒了!!!这正是我所需要的。感谢你们两位!这是我最后的代码:对于您当前的样式表,y您应该使用
count(wd:Report\u Entry[generate-id()=generate id(key('Entry',wd:field)[1]))
。您的样式表当前正在计算
wd:Report\u Entry
元素(6)的数量,而
wd:field
元素
generate-id()
等于
generate-id()
使用
wd:field
元素从键中选择的节点,该元素是该
wd:field
的子元素(该元素不存在,因此它不从键中选择任何内容),导致计数为6。
<xsl:stylesheet xmlns:wd="urn:com.workday.report/CR-INT034-ADP-Garnishment_Disbursements_File-Outbound2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">
    <xsl:strip-space elements="*"/>
    <xsl:output indent="no" method="text"/>

    <xsl:template match="/*">
        <xsl:value-of select="count(distinct-values(wd:Report_Entry))"/>
    </xsl:template>

</xsl:stylesheet>
3