Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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/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
Xml XSLT Muenchian方法复合体_Xml_Xslt_Muenchian Grouping - Fatal编程技术网

Xml XSLT Muenchian方法复合体

Xml XSLT Muenchian方法复合体,xml,xslt,muenchian-grouping,Xml,Xslt,Muenchian Grouping,我尝试使用muenchian方法来选择不同的选项,但我没有得到我需要的结果 这是我的意见: <?xml version="1.0" encoding = "UTF-8"?> <trailers> <ES_PRODUCT year="2014"> <p_product_restrictions> <ES_PRODUCTRESTRICTION> <pr_c

我尝试使用muenchian方法来选择不同的选项,但我没有得到我需要的结果

这是我的意见:

<?xml version="1.0" encoding = "UTF-8"?>
<trailers>
    <ES_PRODUCT year="2014">
        <p_product_restrictions>
            <ES_PRODUCTRESTRICTION>
                <pr_channel>
                    <ESP_CHANNEL name="Channel 1"/>
                </pr_channel>
            </ES_PRODUCTRESTRICTION>
        </p_product_restrictions>
        <trailerProject>
            <wontrailerproject>
                <producer>
                    <ES_PERSON pe_fullname="Erick"/>
                </producer>
            </wontrailerproject>
        </trailerProject>
    </ES_PRODUCT>
    <ES_PRODUCT year="2014">
        <p_product_restrictions>
            <ES_PRODUCTRESTRICTION>
                <pr_channel>
                    <ESP_CHANNEL name="Channel 1"/>
                </pr_channel>
            </ES_PRODUCTRESTRICTION>
        </p_product_restrictions>
        <trailerProject>
            <wontrailerproject>
                <producer>
                    <ES_PERSON pe_fullname="Erick"/>
                </producer>
            </wontrailerproject>
        </trailerProject>
    </ES_PRODUCT>
    <ES_PRODUCT year="2014">
        <p_product_restrictions>
            <ES_PRODUCTRESTRICTION>
                <pr_channel>
                    <ESP_CHANNEL name="Channel 1"/>
                </pr_channel>
            </ES_PRODUCTRESTRICTION>
        </p_product_restrictions>
        <trailerProject>
            <wontrailerproject>
                <producer>
                    <ES_PERSON pe_fullname="Erick"/>
                </producer>
            </wontrailerproject>
        </trailerProject>
    </ES_PRODUCT>
    <ES_PRODUCT year="2013">
        <p_product_restrictions>
            <ES_PRODUCTRESTRICTION>
                <pr_channel>
                    <ESP_CHANNEL name="Channel 2"/>
                </pr_channel>
            </ES_PRODUCTRESTRICTION>
        </p_product_restrictions>
        <trailerProject>
            <wontrailerproject>
                <producer>
                    <ES_PERSON pe_fullname="Erick"/>
                </producer>
            </wontrailerproject>
        </trailerProject>
    </ES_PRODUCT>
    <ES_PRODUCT year="2013">
        <p_product_restrictions>
            <ES_PRODUCTRESTRICTION>
                <pr_channel>
                    <ESP_CHANNEL name="Channel 1"/>
                </pr_channel>
            </ES_PRODUCTRESTRICTION>
        </p_product_restrictions>
        <trailerProject>
            <wontrailerproject>
                <producer>
                    <ES_PERSON pe_fullname="Pepe"/>
                </producer>
            </wontrailerproject>
        </trailerProject>
    </ES_PRODUCT>
    <ES_PRODUCT year="2014">
        <p_product_restrictions>
            <ES_PRODUCTRESTRICTION>
                <pr_channel>
                    <ESP_CHANNEL name="Channel 1"/>
                </pr_channel>
            </ES_PRODUCTRESTRICTION>
        </p_product_restrictions>
        <trailerProject>
            <wontrailerproject>
                <producer>
                    <ES_PERSON pe_fullname="Pepe"/>
                </producer>
            </wontrailerproject>
        </trailerProject>
    </ES_PRODUCT>
    <ES_PRODUCT year="2014">
        <p_product_restrictions>
            <ES_PRODUCTRESTRICTION>
                <pr_channel>
                    <ESP_CHANNEL name="Channel 2"/>
                </pr_channel>
            </ES_PRODUCTRESTRICTION>
        </p_product_restrictions>
        <trailerProject>
            <wontrailerproject>
                <producer>
                    <ES_PERSON pe_fullname="Pepe"/>
                </producer>
            </wontrailerproject>
        </trailerProject>
    </ES_PRODUCT>
    <ES_PRODUCT year="2013">
        <p_product_restrictions>
            <ES_PRODUCTRESTRICTION>
                <pr_channel>
                    <ESP_CHANNEL name="Channel 2"/>
                </pr_channel>
            </ES_PRODUCTRESTRICTION>
        </p_product_restrictions>
        <trailerProject>
            <wontrailerproject>
                <producer>
                    <ES_PERSON pe_fullname="Pepe"/>
                </producer>
            </wontrailerproject>
        </trailerProject>
    </ES_PRODUCT>
 <ES_PRODUCT year="2013">
    <p_product_restrictions>
        <ES_PRODUCTRESTRICTION>
            <pr_channel>
                <ESP_CHANNEL name="Channel 2"/>
            </pr_channel>
        </ES_PRODUCTRESTRICTION>
    </p_product_restrictions>
    <trailerProject>
        <wontrailerproject>
            <producer>
                <ES_PERSON pe_fullname="Thomas"/>
            </producer>
        </wontrailerproject>
    </trailerProject>
</ES_PRODUCT>
</trailers>

我的代码(输出为excel格式)


我不知道如何正确地使用muenchian方法在其他组中创建一个组。 谢谢你的帮助。
谢谢

使用键并不遥远,但据我所知,主要问题是每个
语句都有一些嵌套的
xsl:for,这些语句没有考虑上下文。比如说

<xsl:for-each select="$ROOT_A/ES_PRODUCT/trailerProject/wontrailerproject/producer/ES_PERSON[generate-id() = generate-id(key('producers',@pe_fullname)[1])]">
   <xsl:variable name="thisProducer" select="@pe_fullname"/>
  <xsl:for-each select="p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL[generate-id() = generate-id(key('channels',@name)[1])]">
编辑:如果要仅显示链接到所有频道的制作者,而不是所有频道的所有制作者,则需要引用频道和制作者的串联键

<xsl:key name="producers_by_channel" match="trailers/ES_PRODUCT" 
                                     use="concat(p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name, '|', 
                                                 trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname)"/>

你好Tim C,谢谢你的帮助。您的代码比我需要的要近得多,但我需要在每个原始数据中只放入与频道对应的生产者。对于您的代码,每行中的生产者都是相同的。您知道这是否可能吗?这应该是可能的,但您能否修改您的问题以显示一个示例,因为您当前的XML和预期的输出具有包含所有生产者的通道。谢谢是的,对不起。我在原来的问题中添加了一个新节点,其中制作人是Thomas。如果我使用该源代码运行您的代码,结果中thomas将出现在通道1(带0)和通道2(带1)。但是我只需要在第二频道播放托马斯。我已经修改了我的答案,以显示另一个样式表。非常感谢你的帮助,蒂姆!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"
            xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:output encoding="utf-8" indent="yes"/>
<xsl:key name="producers" match="trailers/ES_PRODUCT/trailerProject/wontrailerproject/producer/ES_PERSON" use="@pe_fullname"/>
<xsl:key name="channels" match="trailers/ES_PRODUCT/p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL" use="@name"/>
<xsl:key name="year" match="trailers/ES_PRODUCT" use="@year"/>
<xsl:key name="full" match="trailers/ES_PRODUCT" use="concat(p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name, '|', 
                                                             trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname, '|',
                                                             @year)"/>

<xsl:template match="/">
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
              xmlns:html="http://www.w3.org/TR/REC-html40">
        <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">

        </DocumentProperties>
        <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
            <AllowPNG/>
        </OfficeDocumentSettings>
        <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
            <WindowHeight>11595</WindowHeight>
            <WindowWidth>19200</WindowWidth>
            <WindowTopX>0</WindowTopX>
            <WindowTopY>0</WindowTopY>
            <ProtectStructure>False</ProtectStructure>
            <ProtectWindows>False</ProtectWindows>
        </ExcelWorkbook>
        <Styles>
            <Style ss:ID="Default" ss:Name="Normal">
                <Alignment ss:Vertical="Bottom"/>
                <Borders/>
                <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
                <Interior/>
                <NumberFormat/>
                <Protection/>
            </Style>
            <Style ss:ID="s70">
                <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
                <Interior ss:Color="#FFC000" ss:Pattern="Solid"/>
            </Style>
            <Style ss:ID="s74">
                <Borders>
                    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
                    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
                    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
                </Borders>
            </Style>
            <Style ss:ID="s75">
                <Borders>
                    <Border ss:Position="Bottom" ss:LineStyle="Double" ss:Weight="3"/>
                    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
                    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
                    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
                </Borders>
                <Interior ss:Color="#92D050" ss:Pattern="Solid"/>
            </Style>
        </Styles>
        <Worksheet ss:Name="Hoja1">
            <Table x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15">
                <Column ss:Width="66"/>
                <Column ss:AutoFitWidth="0" ss:Width="69"/>
                <xsl:variable name="ROOT_A" select="trailers"/>
                <xsl:variable name="distinct_channels" select="trailers/ES_PRODUCT/p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL[generate-id() = generate-id(key('channels',@name)[1])]" />
                <xsl:variable name="distinct_producers" select="$ROOT_A/ES_PRODUCT/trailerProject/wontrailerproject/producer/ES_PERSON[generate-id() = generate-id(key('producers',@pe_fullname)[1])]" />
                <xsl:variable name="distinct_years" select="$ROOT_A/ES_PRODUCT[generate-id() = generate-id(key('year',@year)[1])]" />
                <xsl:for-each select="$distinct_channels">
                    <xsl:variable name="thisChannel" select="@name"/>

                    <Row ss:Height="15.75">
                        <Cell ss:StyleID="s75">
                            <Data ss:Type="String">
                                <xsl:value-of select="$thisChannel"/>
                            </Data>
                        </Cell>
                        <xsl:for-each select="$distinct_producers">
                            <xsl:variable name="thisProducer" select="@pe_fullname"/>

                                <Cell ss:StyleID="s75">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$thisProducer"/>
                                    </Data>
                                </Cell>
                        </xsl:for-each>
                    </Row>

                    <xsl:for-each select="$distinct_years">
                        <xsl:variable name="thisYear" select="@year"/>

                            <Row ss:Height="15.75">
                                <Cell ss:StyleID="s74">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$thisYear"/>
                                    </Data>
                                </Cell>
                                <xsl:for-each select="$distinct_producers">
                                    <xsl:variable name="thisProducer" select="@pe_fullname"/>
                                        <Cell ss:StyleID="s74">
                                            <Data ss:Type="Number">
                                                <xsl:value-of select="count(key('full', concat($thisChannel, '|', $thisProducer, '|', $thisYear)))"/>
                                            </Data>
                                        </Cell>
                                </xsl:for-each>
                            </Row>
                    </xsl:for-each>
                </xsl:for-each>
            </Table>
            <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
                <PageSetup>
                    <Header x:Margin="0.3"/>
                    <Footer x:Margin="0.3"/>
                    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
                </PageSetup>
                <Print>
                    <ValidPrinterInfo/>
                    <HorizontalResolution>300</HorizontalResolution>
                    <VerticalResolution>300</VerticalResolution>
                </Print>
                <Selected/>
                <Panes>
                    <Pane>
                        <Number>3</Number>
                        <ActiveRow>6</ActiveRow>
                        <ActiveCol>2</ActiveCol>
                    </Pane>
                </Panes>
                <ProtectObjects>False</ProtectObjects>
                <ProtectScenarios>False</ProtectScenarios>
            </WorksheetOptions>
        </Worksheet>
    </Workbook>
</xsl:template>
</xsl:stylesheet>
<xsl:key name="producers_by_channel" match="trailers/ES_PRODUCT" 
                                     use="concat(p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name, '|', 
                                                 trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname)"/>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"
            xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:output encoding="utf-8" indent="yes"/>

<xsl:key name="channels" match="trailers/ES_PRODUCT" use="p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name"/>
<xsl:key name="year" match="trailers/ES_PRODUCT" use="@year"/>
<xsl:key name="producers_by_channel" match="trailers/ES_PRODUCT" 
                                     use="concat(p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name, '|', 
                                                 trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname)"/>
<xsl:key name="full" match="trailers/ES_PRODUCT" use="concat(p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name, '|', 
                                                             trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname, '|',
                                                             @year)"/>

<xsl:template match="/">
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
              xmlns:html="http://www.w3.org/TR/REC-html40">
        <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">

        </DocumentProperties>
        <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
            <AllowPNG/>
        </OfficeDocumentSettings>
        <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
            <WindowHeight>11595</WindowHeight>
            <WindowWidth>19200</WindowWidth>
            <WindowTopX>0</WindowTopX>
            <WindowTopY>0</WindowTopY>
            <ProtectStructure>False</ProtectStructure>
            <ProtectWindows>False</ProtectWindows>
        </ExcelWorkbook>
        <!-- Styles go here -->
        <Worksheet ss:Name="Hoja1">
            <Table x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15">
                <Column ss:Width="66"/>
                <Column ss:AutoFitWidth="0" ss:Width="69"/>
                <xsl:variable name="ROOT_A" select="trailers"/>
                <xsl:variable name="distinct_channels" select="$ROOT_A/ES_PRODUCT[generate-id() = generate-id(key('channels',p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name)[1])]" />
                <xsl:variable name="distinct_years" select="$ROOT_A/ES_PRODUCT[generate-id() = generate-id(key('year',@year)[1])]" />
                <xsl:for-each select="$distinct_channels">
                    <xsl:variable name="thisChannel" select="p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name"/>
                    <xsl:variable name="distinct_producers" select="key('channels', $thisChannel)[generate-id() = generate-id(key('producers_by_channel',concat($thisChannel, '|', trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname))[1])]" />
                    <Row ss:Height="15.75">
                        <Cell ss:StyleID="s75">
                            <Data ss:Type="String">
                                <xsl:value-of select="$thisChannel"/>
                            </Data>
                        </Cell>
                        <xsl:for-each select="$distinct_producers">
                            <xsl:variable name="thisProducer" select="trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname"/>

                                <Cell ss:StyleID="s75">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$thisProducer"/>
                                    </Data>
                                </Cell>
                        </xsl:for-each>
                    </Row>

                    <xsl:for-each select="$distinct_years">
                        <xsl:variable name="thisYear" select="@year"/>

                            <Row ss:Height="15.75">
                                <Cell ss:StyleID="s74">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$thisYear"/>
                                    </Data>
                                </Cell>
                                <xsl:for-each select="$distinct_producers">
                                    <xsl:variable name="thisProducer" select="trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname"/>
                                        <Cell ss:StyleID="s74">
                                            <Data ss:Type="Number">
                                                <xsl:value-of select="count(key('full', concat($thisChannel, '|', $thisProducer, '|', $thisYear)))"/>
                                            </Data>
                                        </Cell>
                                </xsl:for-each>
                            </Row>
                    </xsl:for-each>
                </xsl:for-each>
            </Table>
            <!-- WorksheetOptions go here -->
        </Worksheet>
    </Workbook>
</xsl:template>
</xsl:stylesheet>