Xml 否则需要xsl:for-each吗?
这是我的xslt的最后一部分,有人对我遗漏的内容有什么建议吗? 也许xsl:否则不需要xsl:for-each或者我的循环不正确? 我已经尝试过从xsl:otherwise部分中删除“祖先”,但成功了。 我在xsl:others部分中尝试了xsl:variable(命名成本),但它也不起作用 我的xml:Xml 否则需要xsl:for-each吗?,xml,xpath,xslt-1.0,Xml,Xpath,Xslt 1.0,这是我的xslt的最后一部分,有人对我遗漏的内容有什么建议吗? 也许xsl:否则不需要xsl:for-each或者我的循环不正确? 我已经尝试过从xsl:otherwise部分中删除“祖先”,但成功了。 我在xsl:others部分中尝试了xsl:variable(命名成本),但它也不起作用 我的xml: <?xml version="1.0" encoding="UTF-8"?> <contracts> <ES_CM
<?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>
<!-- Cost -->
<Cell ss:Index="2" ss:StyleID="header">
<Data ss:Type="String">Cost</Data>
</Cell>
<!-- Dubbing Supplier -->
<Cell ss:Index="3" ss:StyleID="header">
<Data ss:Type="String">Dubbing Supplier</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>
<Cell ss:Index="1" >
<Data ss:Type="String">
<xsl:value-of select="@contractName"/>
</Data>
</Cell>
<Cell ss:Index="2" >
<Data ss:Type="String">
<xsl:value-of select="productInContracts/ES_CMProductInContract/broadcastRights/ES_CM2BROADCASTRIGHT/broadcastRightGroup/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition/costGroup/ESP_2COSTGROUP/@name"/>
</Data>
</Cell>
<Cell ss:Index="3" >
<Data ss:Type="String">
<xsl:value-of select="productInContracts/ES_CMProductInContract/broadcastRights/ES_CM2BROADCASTRIGHT/broadcastRightGroup/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition/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>
<Cell ss:Index="1" >
<Data ss:Type="String">
<xsl:value-of select="ancestor::ES_CMContract/@contractName"/>
</Data>
</Cell>
<Cell ss:Index="2" >
<Data ss:Type="String">
<xsl:value-of select="ancestor::ES_CMContract/productInContracts/ES_CMProductInContract/broadcastRights/ES_CM2BROADCASTRIGHT/broadcastRightGroup/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition/costGroup/ESP_2COSTGROUP/@name"/>
</Data>
</Cell>
<Cell ss:Index="3" >
<Data ss:Type="String">
<xsl:value-of select="ancestor::ES_CMContract/productInContracts/ES_CMProductInContract/broadcastRights/ES_CM2BROADCASTRIGHT/broadcastRightGroup/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition/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”
合同名称
成本
配音供应商
结果:
我想要的是:
较难的部分:
我怎样才能像这样分离costgrp:
感谢
xsl:for中的表达式相对于它设置的上下文节点的每个工作。
因此,只需更改
<xsl:value-of select="productInContracts/ES_CMProductInContract/broadcastRights/ES_CM2BROADCASTRIGHT/broadcastRightGroup/ES_BROADCASTRIGHTGROUP/costDefinitions/ES_CM2CostDefinition/costGroup/ESP_2COSTGROUP/@name"/>
到
在这两种情况下。
现在您应该得到所需的输出
但是,在上面的示例中
<xsl:when test="productInContracts/ES_CMProductInContract/episodesInContract">
永远也达不到。所以这可能没有必要。在回答这个问题之后,问题被更新了,内容太宽泛了。谢谢,它工作得很好。你能帮我回答“难的部分:我怎样才能像这样分开成本组:”部分?啊,我明白了,我会把这个代码放到她的新问题中,谢谢
<xsl:when test="productInContracts/ES_CMProductInContract/episodesInContract">