Xml XSLT 1.0元素中出现意外的标记问题

Xml XSLT 1.0元素中出现意外的标记问题,xml,xpath,xslt-1.0,Xml,Xpath,Xslt 1.0,我想在xsl:otherwise元素中分离我的成本。 我已经尝试了使用祖先的otherwise元素中的XPATH,但无法获取任何数据。 我已经在没有祖先的其他元素中尝试了XPATH,但它也不起作用。 在其他元素下解决这个问题是很重要的 我想这样分开所有成本: 我的XML: <?xml version="1.0" encoding="UTF-8"?> <contracts> <ES_CMContract contrac

我想在xsl:otherwise元素中分离我的成本。 我已经尝试了使用祖先的otherwise元素中的XPATH,但无法获取任何数据。 我已经在没有祖先的其他元素中尝试了XPATH,但它也不起作用。 在其他元素下解决这个问题是很重要的

我想这样分开所有成本:

我的XML:

<?xml version="1.0" encoding="UTF-8"?>
<contracts>
    <ES_CMContract contractName="test_01">
        <productInContracts>
            <ES_CMProductInContract>
                <broadcastRights>
                    <ES_CM2BROADCASTRIGHT>
                        <broadcastRightGroup>
                            <ES_BROADCASTRIGHTGROUP>
                                <costDefinitions>
                                    <ES_CM2CostDefinition>
                                        <costGroup>
                                            <ESP_2COSTGROUP name="Distributor"/>
                                        </costGroup>
                                        <involvedParty>
                                            <ES_FIRM f_name="FREMANTLE MEDIA"/>
                                        </involvedParty>
                                    </ES_CM2CostDefinition>
                                    <ES_CM2CostDefinition>
                                        <costGroup>
                                            <ESP_2COSTGROUP name="Material Cost"/>
                                        </costGroup>
                                        <involvedParty>
                                            <ES_FIRM f_name="FREMANTLE MEDIA"/>
                                        </involvedParty>
                                    </ES_CM2CostDefinition>
                                    <ES_CM2CostDefinition>
                                        <costGroup>
                                            <ESP_2COSTGROUP name="Dubbing Cost"/>
                                        </costGroup>
                                        <involvedParty>
                                            <ES_FIRM f_name="FREMANTLE MEDIA"/>
                                        </involvedParty>
                                    </ES_CM2CostDefinition>
                                    <ES_CM2CostDefinition>
                                        <costGroup>
                                            <ESP_2COSTGROUP name="Technical Cost"/>
                                        </costGroup>
                                        <involvedParty>
                                            <ES_FIRM f_name="FREMANTLE MEDIA"/>
                                        </involvedParty>
                                    </ES_CM2CostDefinition>
                                </costDefinitions>
                            </ES_BROADCASTRIGHTGROUP>
                        </broadcastRightGroup>
                    </ES_CM2BROADCASTRIGHT>
                </broadcastRights>
            </ES_CMProductInContract>
        </productInContracts>
    </ES_CMContract>
    <ES_CMContract contractName="test_02">
        <productInContracts>
            <ES_CMProductInContract>
                <broadcastRights>
                    <ES_CM2BROADCASTRIGHT>
                        <broadcastRightGroup>
                            <ES_BROADCASTRIGHTGROUP>
                                <costDefinitions>
                                    <ES_CM2CostDefinition>
                                        <costGroup>
                                            <ESP_2COSTGROUP name="Distributor"/>
                                        </costGroup>
                                        <involvedParty>
                                            <ES_FIRM f_name="Walt Disney Co Ltd."/>
                                        </involvedParty>
                                    </ES_CM2CostDefinition>
                                    <ES_CM2CostDefinition>
                                        <costGroup>
                                            <ESP_2COSTGROUP name="Dubbing Cost"/>
                                        </costGroup>
                                        <involvedParty>
                                            <ES_FIRM f_name="GRANDVIEW"/>
                                        </involvedParty>
                                    </ES_CM2CostDefinition>
                                </costDefinitions>
                            </ES_BROADCASTRIGHTGROUP>
                        </broadcastRightGroup>
                    </ES_CM2BROADCASTRIGHT>
                </broadcastRights>
            </ES_CMProductInContract>
        </productInContracts>
    </ES_CMContract>
</contracts>

我的XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<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:template match="contracts">
        
        <xsl:processing-instruction name="mso-application">progid="Excel.Sheet"</xsl:processing-instruction>
        <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
            <Styles>
                <Style ss:ID="header" ss:Name="Normal">
                    <Font ss:FontName="Verdana" ss:Bold="1"/>
                </Style>
            </Styles>
            
            <Worksheet ss:Name="Report">
                <Table>
                    <Row ss:Index="1">
                        <!-- contract name -->
                        <Cell ss:Index="1" ss:StyleID="header">
                            <Data ss:Type="String">contract name</Data>
                        </Cell>
                        <!-- Distributor_01 -->
                        <Cell ss:Index="2" ss:StyleID="header">
                            <Data ss:Type="String">Cost_1</Data>
                        </Cell>
                        <!-- Firm_01 -->
                        <Cell ss:Index="3" ss:StyleID="header">
                            <Data ss:Type="String">firm_1</Data>
                        </Cell>
                        <!-- Distributor_02 -->
                        <Cell ss:Index="4" ss:StyleID="header">
                            <Data ss:Type="String">Cost_2</Data>
                        </Cell>
                        <!-- Firm_02 -->
                        <Cell ss:Index="5" ss:StyleID="header">
                            <Data ss:Type="String">firm_2</Data>
                        </Cell>
                        <!-- Distributor_03 -->
                        <Cell ss:Index="6" ss:StyleID="header">
                            <Data ss:Type="String">Cost_3</Data>
                        </Cell>
                        <!-- Firm_03 -->
                        <Cell ss:Index="7" ss:StyleID="header">
                            <Data ss:Type="String">firm_3</Data>
                        </Cell>
                        <!-- Distributor_04 -->
                        <Cell ss:Index="8" ss:StyleID="header">
                            <Data ss:Type="String">Cost_4</Data>
                        </Cell>
                        <!-- Firm_04 -->
                        <Cell ss:Index="9" ss:StyleID="header">
                            <Data ss:Type="String">firm_4</Data>
                        </Cell>
                    </Row>
                    
                    <xsl:for-each select="ES_CMContract">               
                        <xsl:variable name="cost" select="productInContracts/ES_CMProductInContract/broadcastRights/ES_CM2BROADCASTRIGHT/broadcastRightGroup/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition"/>             
                        <xsl:choose>
                            <xsl:when test="productInContracts/ES_CMProductInContract/episodesInContract">
                                <xsl:for-each select="productInContracts/ES_CMProductInContract/broadcastRights/ES_CM2BROADCASTRIGHT/broadcastRightGroup/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition">  
                                    <Row>
                                        <!-- contract name -->
                                        <Cell ss:Index="1" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="@contractName"/>
                                            </Data>
                                        </Cell>
                                        <!-- Distributor_01 -->
                                        <Cell ss:Index="2" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Distributor']/costGroup/ESP_2COSTGROUP/@name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Firm_01 -->
                                        <Cell ss:Index="3" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Distributor']/involvedParty/ES_FIRM/@f_name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Distributor_02 -->
                                        <Cell ss:Index="4" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Material Cost']/costGroup/ESP_2COSTGROUP/@name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Firm_02 -->
                                        <Cell ss:Index="5" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Material Cost']/involvedParty/ES_FIRM/@f_name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Distributor_03 -->
                                        <Cell ss:Index="6" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Dubbing Cost']/costGroup/ESP_2COSTGROUP/@name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Firm_03 -->
                                        <Cell ss:Index="7" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Dubbing Cost']/involvedParty/ES_FIRM/@f_name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Distributor_04 -->
                                        <Cell ss:Index="8" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Technical Cost']/costGroup/ESP_2COSTGROUP/@name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Firm_04 -->
                                        <Cell ss:Index="9" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Technical Cost']/involvedParty/ES_FIRM/@f_name"/>
                                            </Data>
                                        </Cell>
                                    </Row>
                                </xsl:for-each>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:for-each select="productInContracts/ES_CMProductInContract/broadcastRights/ES_CM2BROADCASTRIGHT/broadcastRightGroup/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition">
                                    <Row>
                                        <!-- contract name -->
                                        <Cell ss:Index="1" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/@contractName"/>
                                            </Data>
                                        </Cell>
                                        <!-- Distributor_01 -->
                                        <Cell ss:Index="2" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="[costGroup/ESP_2COSTGROUP/@name='Distributor']/costGroup/ESP_2COSTGROUP/@name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Firm_01 -->
                                        <Cell ss:Index="3" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Distributor']/involvedParty/ES_FIRM/@f_name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Distributor_02 -->
                                        <Cell ss:Index="4" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Material Cost']/costGroup/ESP_2COSTGROUP/@name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Firm_02 -->
                                        <Cell ss:Index="5" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Material Cost']/involvedParty/ES_FIRM/@f_name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Distributor_03 -->
                                        <Cell ss:Index="6" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Dubbing Cost']/costGroup/ESP_2COSTGROUP/@name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Firm_03 -->
                                        <Cell ss:Index="7" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Dubbing Cost']/involvedParty/ES_FIRM/@f_name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Distributor_04 -->
                                        <Cell ss:Index="8" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Technical Cost']/costGroup/ESP_2COSTGROUP/@name"/>
                                            </Data>
                                        </Cell>
                                        <!-- Firm_04 -->
                                        <Cell ss:Index="9" >
                                            <Data ss:Type="String">
                                                <xsl:value-of select="ancestor::ES_CMContract/broadcastRightGroups/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition[costGroup/ESP_2COSTGROUP/@name='Technical Cost']/involvedParty/ES_FIRM/@f_name"/>
                                            </Data>
                                        </Cell>
                                    </Row>
                                </xsl:for-each>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:for-each>
                </Table>
            </Worksheet>
        </Workbook>
    </xsl:template>
    
</xsl:stylesheet>

progid=“Excel.Sheet”
合同名称
成本1
商号1
成本2
商号2
成本3
商号3
成本4
商号4
<xsl:template match="ES_CM2CostDefinition" mode="Distributor_name"> <!-- Distributor name  -->
    <xsl:if test="costGroup/ESP_2COSTGROUP/@name = 'Distributor'">
        <xsl:value-of select="costGroup/ESP_2COSTGROUP/@name"/>
    </xsl:if>
</xsl:template>


<xsl:template match="ES_CM2CostDefinition" mode="Distributor_Supplier"> <!-- Distributor Supplier  -->
    <xsl:if test="costGroup/ESP_2COSTGROUP/@name = 'Distributor'">
        <xsl:value-of select="involvedParty/ES_FIRM/@f_name"/>
    </xsl:if>
</xsl:template>
select="[costGroup/ESP_2COSTGROUP/@name='Distributor']/costGroup/ESP_2COSTGROUP/@name"