Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.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
Xml 按变量分组的XSLT_Xml_Xslt_Xslt 1.0_Xslt Grouping_Muenchian Grouping - Fatal编程技术网

Xml 按变量分组的XSLT

Xml 按变量分组的XSLT,xml,xslt,xslt-1.0,xslt-grouping,muenchian-grouping,Xml,Xslt,Xslt 1.0,Xslt Grouping,Muenchian Grouping,输入: 3. 1319648 11310337 189221 3. 1319652 1320566 1319575 11310281 189221 3. 1319652 1320614 1319623 11310281 189221 3. 1319652 1320656 1319667 11310281 189221 XSL: 各位好, 谢谢你的帮助。 目标是检查我们构建标记的每个不同的VRPlanID值 如果标记的id部分中对应的MSTP、MSONPC(不同)不为null/空,则将它们

输入:


3.
1319648
11310337
189221
3.
1319652
1320566
1319575
11310281
189221
3.
1319652
1320614
1319623
11310281
189221
3.
1319652
1320656
1319667
11310281
189221
XSL:


各位好,

谢谢你的帮助。 目标是检查我们构建标记的每个不同的VRPlanID值 如果标记的id部分中对应的MSTP、MSONPC(不同)不为null/空,则将它们分组。 因此,我们在VRPlanID之后分组,然后从MSTP/MSONPC的每个记录中获得不同的值。 如果它们是空的,那么只需构建一个伪/null消息/标记。 这是可行的,但我有两个问题: -我总是在最后一个id后面有一个“,”逗号,我不知道为什么 -我不再需要连接,但我希望每个ID都有一个标记任务

因此,期望的输出是:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"> 
    <xsl:output method="xml" /> 
    <xsl:template name="task-attr">
    <!--parameter to filter per VRPlanId-->     
    <xsl:param name="param.VRPlanId"/>              
    <xsl:variable name="var.mstp">                      
        <xsl:for-each 


  select="/output/meta2/Comenzi/output_getquerydata/queries/query/queryResults/rec
    ord[column[@name='VRPlanId'] = $param.VRPlanId]">
             <!--preventing empty blocks and duplicates for MSTP-->          
             <xsl:if test="string-length(column[@name='MSSinergieTaskP']) &gt;0 
    and not(preceding::record[column[@name='MSSinergieTaskP']/text() = 
    current()/column[@name='MSSinergieTaskP']/text()])">                   
                <xsl:value-of select="concat(column[@name='MSSinergieTaskP'], 
    ',')"/>              
            </xsl:if>                                       
        </xsl:for-each>                             
       </xsl:variable>     
     <xsl:variable name="var.msonpc">                        
        <xsl:for-each 

 select="/output/meta2/Comenzi/output_getquerydata/queries/query/queryResults/re
    cord[column[@name='VRPlanId'] = $param.VRPlanId]">
            <!--preventing empty blocks and duplicates for MSONPC-->            
            <xsl:if test="string-length(column[@name='MSSinergieTaskNP']) &gt;0 
    and not(preceding::record[column[@name='MSSinergieTaskNP']/text() = 
    current()/column[@name='MSSinergieTaskNP']/text()])">                 
                <xsl:value-of select="concat(column[@name='MSSinergieTaskNP'], 
    ',')"/>                
            </xsl:if>                                       
        </xsl:for-each>                             
     </xsl:variable>
     <!--concat all non-duplicates MSTP and MSONPC without last delimiter--> 
     <xsl:value-of select="concat($var.mstp, substring($var.msonpc, 1, string-
    length($var.msonpc)-1))"/>     
    </xsl:template>

    <xsl:template match="/">        
     <output>            
        <xsl:for-each 

 select="/output/meta2/Comenzi/output_getquerydata/queries/query/queryResults/record">             
             <xsl:if test ="not(preceding::record[column[@name='VRPlanId']/text() = 
    current()/column[@name='VRPlanId']/text()])">                    
                 <xsl:variable name="task.id">                                                   
                    <xsl:call-template name="task-attr">
                        <!--as input parameter put non-duplicate VRPlanId-->                                                            
                        <xsl:with-param name="param.VRPlanId" 
   select="column[@name='VRPlanId']"/>                                                   
                    </xsl:call-template>                                    
                </xsl:variable>
                <!--if all non-duplicates MSTP and MSONPC will be blank block 
   Cdo won't be created-->                   
                 <xsl:if test="string-length($task.id) &gt;0">                       
                     <Cdo>                           
                        <parameters>                                
                            <task>                                                          
                                <xsl:attribute name="id">                                                       
                                    <xsl:value-of select="$task.id"/>               
                                </xsl:attribute>                                
                            </task>                             
                            <action>                                                            
                                <xsl:attribute name="id">                                                                           
                                    <xsl:value-of 
  select="column[@name='VRPlanId']"/>                                                               
                                </xsl:attribute>                                
                            </action>                                           
                        </parameters>                       
                    </Cdo>                                      
                </xsl:if>               
            </xsl:if>           
        </xsl:for-each>                     
      </output>   
    </xsl:template>
    </xsl:stylesheet>

请记住,标记MSSinergieTaskP和MSSinergieTaskNP之间的任何组合都是可能的。所以一个可能是空的,另一个不是。或者一条记录为空,然后下一条记录有一个值。 我只是想得到任何组合的不同值,对于这两个组合,对于每个不同的VRIdTask

我似乎无法让它工作。
有什么建议吗?

对于XSLT1.0中的分组,最有效的解决方案是使用

在这种情况下,可以使用属性
@name='VRPlanId'
中的值创建分组键

    <output>
    <Cdo>
        <parameters>
            <task id="1319575"/>
            <task id="1319623"/>
            <task id="1319667"/>
            <action id="11310281"/>
        </parameters>
    </Cdo>
</output>
对于
记录
模板,检查
MSSinergieTaskP
MSSinergieTaskNP
中的任何一个是否具有值,然后循环通过分组节点从
MSSinergieTaskP
获取值

下面是完整的XSLT

<xsl:template match="output">
    <xsl:copy>
        <Cdo>
            <parameters>
                <xsl:apply-templates select="//record[generate-id() = generate-id(key('vrPlanId', column[@name='VRPlanId'])[1])]" />
            </parameters>
        </Cdo>
    </xsl:copy>
</xsl:template>

这提供了所需的输出

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" />
    <xsl:strip-space elements="*" />

    <xsl:key name="vrPlanId" match="record" use="column[@name='VRPlanId']" />

    <xsl:template match="output">
        <xsl:copy>
            <Cdo>
                <parameters>
                    <xsl:apply-templates select="//record[generate-id() = generate-id(key('vrPlanId', column[@name='VRPlanId'])[1])]" />
                </parameters>
            </Cdo>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="record">
        <xsl:if test="column[@name='MSSinergieTaskP'] != '' or column[@name='MSSinergieTaskNP'] != ''">
            <action>
                <xsl:attribute name="id">
                    <xsl:value-of select="column[@name='VRPlanId']" />
                </xsl:attribute>
            </action>
            <xsl:for-each select="key('vrPlanId', column[@name='VRPlanId'])">
                <task>
                    <xsl:attribute name="id">
                        <xsl:value-of select="column[@name='MSSinergieTaskP']" />
                    </xsl:attribute>
                </task>
            </xsl:for-each>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

对于XSLT 1.0中的分组,最有效的解决方案是使用

在这种情况下,可以使用属性
@name='VRPlanId'
中的值创建分组键

    <output>
    <Cdo>
        <parameters>
            <task id="1319575"/>
            <task id="1319623"/>
            <task id="1319667"/>
            <action id="11310281"/>
        </parameters>
    </Cdo>
</output>
对于t
<xsl:template match="output">
    <xsl:copy>
        <Cdo>
            <parameters>
                <xsl:apply-templates select="//record[generate-id() = generate-id(key('vrPlanId', column[@name='VRPlanId'])[1])]" />
            </parameters>
        </Cdo>
    </xsl:copy>
</xsl:template>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" />
    <xsl:strip-space elements="*" />

    <xsl:key name="vrPlanId" match="record" use="column[@name='VRPlanId']" />

    <xsl:template match="output">
        <xsl:copy>
            <Cdo>
                <parameters>
                    <xsl:apply-templates select="//record[generate-id() = generate-id(key('vrPlanId', column[@name='VRPlanId'])[1])]" />
                </parameters>
            </Cdo>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="record">
        <xsl:if test="column[@name='MSSinergieTaskP'] != '' or column[@name='MSSinergieTaskNP'] != ''">
            <action>
                <xsl:attribute name="id">
                    <xsl:value-of select="column[@name='VRPlanId']" />
                </xsl:attribute>
            </action>
            <xsl:for-each select="key('vrPlanId', column[@name='VRPlanId'])">
                <task>
                    <xsl:attribute name="id">
                        <xsl:value-of select="column[@name='MSSinergieTaskP']" />
                    </xsl:attribute>
                </task>
            </xsl:for-each>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>
<output>
    <Cdo>
        <parameters>
            <action id="11310281" />
            <task id="1319575" />
            <task id="1319623" />
            <task id="1319667" />
        </parameters>
    </Cdo>
</output>