我有一個xml,我試圖添加一個新元素,然後在特定條件下分配值。 一切工作正常。 但是,它似乎將新元素添加到父節點。 有人可以幫我找出問題。XSLT將新元素添加到當前節點
以下是完整的XSLT。但是我對最後一個模板有問題。
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
xmlns:ns0="http://somenamespace">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="ns0:Cedent/ns0:Party/ns0:Id[. = '']">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="../../following-sibling::ns0:Broker[1]/ns0:Party/ns0:Id/node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="ns0:Cedent/ns0:Party/ns0:Id/@Agency[. = '']">
<xsl:attribute name="Agency">DUNS_dun_and_bradstreet</xsl:attribute>
</xsl:template>
<xsl:template match="ns0:Reinsurer[not(ns0:Party/ns0:Id != '') and not(ns0:Reinsurer/ns0:Party/ns0:Id/@Agency[. != ''])]" />
<xsl:template match="ns0:Reinsurer/ns0:Contact[not(ns0:PersonName !='')]" />
<xsl:template match="ns0:Reinsurer/ns0:Contact/*[not(node())]" />
<xsl:template match="ns0:Broker/ns0:Contact/ns0:Telephone[not(node())]" />
<xsl:template match="ns0:ServiceProvider[. = '6']" />
<xsl:template match="ns0:ServiceProvider[not(ns0:Party/ns0:Id != '') and not(ns0:Reinsurer/ns0:Party/ns0:Id/@Agency[. != ''])]" />
<xsl:template match="ns0:Contract/ns0:ContractGroupName[not(node())]" />
<xsl:template match="ns0:Endorsement[ns0:Placing/ns0:PlacingStage = 'endorsement']" />
<xsl:template match="ns0:Endorsement/ns0:EndorsementReference[not(node())]" />
<xsl:template match="ns0:Endorsement/ns0:EndorsementName[not(node())]" />
<xsl:template match="ns0:Endorsement/ns0:Description[not(node())]" />
<xsl:template match="ns0:Endorsement/ns0:EffectiveDate[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:BrokerSharePercentage[not(node()) and ns0:ContractSection/ns0:BrokerSharePercentage/ns0:Rate > 0]" />
<xsl:template match="ns0:ContractSection/ns0:RiskLocation[not(node()) or (ns0:PlacingTransactionFunction = 'request_for_line_or_binder' or ns0:PlacingTransactionFunction = 'signed_line_advice' or ns0:PlacingTransactionFunction = 'quotation_request' or ns0:PlacingTransactionFunction = 'endorsement_request')]" />
<xsl:template match="ns0:ContractSection/ns0:RiskLocation/ns0:Location/ns0:Supraentity[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:RiskLocation/ns0:Location/ns0:Country[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:PerilsIncluded[not(ns0:Peril/ns0:PerilType !='')]" />
<xsl:template match="ns0:ContractSection/ns0:Brokerage[descendant::ns0:Rate = '' and not(ns0:ContractSection/ns0:BrokeragePercentage/ns0:Rate > 0)]" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:Reinsurer[descendant::ns0:Id = '' and not(ns0:Party/ns0:Id/@Agency[. != ''])]" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:ReinsurerContractReference[not(node())]" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:ReinsurerQuoteMaximumSharePercentage[descendant::ns0:Rate = '']" />
<xsl:template match="ns0:ContractSection/ns0:ContractMarket/ns0:ReinsurerWrittenPercentage[descendant::ns0:Rate = '' and ns0:PlacingTransactionFunction = 'signed_line_advice']" />
<xsl:template match="ns0:Placing">
<xsl:variable name="percentage-rate" select="ns0:ContractSection/ns0:OrderPercentage/ns0:Rate"/>
<xsl:copy>
<ns0:ContractSection>
<ns0:LinesPercentageOfOrderIndicator>
<xsl:value-of select="ns0:PlacingTransactionFunction = 'signed_line_advice' and $percentage-rate > 100"/>
</ns0:LinesPercentageOfOrderIndicator>
<xsl:apply-templates select="ns0:ContractSection/ns0:ContractMarket"/>
</ns0:ContractSection>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
源XML:
<ns0:Root xmlns:ns0="http://somenamespace">
<ns0:Placing Sender="broker" Receiver="serviceprovider">
<ns0:UUId>GUID</ns0:UUId>
<ns0:BrokerReference>2B3B8992-3185-48EE-A030-0F61EFF7C7EB</ns0:BrokerReference>
<ns0:ServiceProviderReference>16</ns0:ServiceProviderReference>
<ns0:PlacingStage>order</ns0:PlacingStage>
<ns0:PlacingTransactionFunction>signed_line_advice</ns0:PlacingTransactionFunction>
<ns0:TransactionReasonDescription></ns0:TransactionReasonDescription>
<ns0:Cedent>
<ns0:Party>
<ns0:Id Agency=""></ns0:Id>
<ns0:Name>Bahamas First General Insurance Co/Aon Benfield Canada</ns0:Name>
</ns0:Party>
</ns0:Cedent>
<ns0:Reinsurer>
<ns0:Party>
<ns0:Id Agency=""></ns0:Id>
<ns0:Name>RI3K</ns0:Name>
</ns0:Party>
<ns0:Contact>
<ns0:PersonName>test</ns0:PersonName>
<ns0:Telephone></ns0:Telephone>
<ns0:Email>[email protected]</ns0:Email>
</ns0:Contact>
</ns0:Reinsurer>
<ns0:Broker>
<ns0:Party>
<ns0:Id Agency="DUNS_dun_and_bradstreet">292320710</ns0:Id>
<ns0:Name>Aon Benfield UK</ns0:Name>
</ns0:Party>
<ns0:Contact>
<ns0:PersonName>Jenny Edwards</ns0:PersonName>
<ns0:Telephone>reinsurance_contract</ns0:Telephone>
<ns0:Email>[email protected]</ns0:Email>
</ns0:Contact>
</ns0:Broker>
<ns0:ServiceProvider>
<ns0:Party>
<ns0:Id Agency="DUNS_dun_and_bradstreet">239195295</ns0:Id>
</ns0:Party>
</ns0:ServiceProvider>
<ns0:Contract>
<ns0:ContractName>FINCO QUOTA SHARE TREATY</ns0:ContractName>
<ns0:ContractGroupName>BFG FINCO QUOTA SHARE TREATY</ns0:ContractGroupName>
<ns0:ContractType>0</ns0:ContractType>
<ns0:BrokerReference>B110813BDO1053</ns0:BrokerReference>
<ns0:BrokerGroupReference>200153436</ns0:BrokerGroupReference>
<ns0:BrokerRiskReference>13BDO1053</ns0:BrokerRiskReference>
</ns0:Contract>
<ns0:Endorsement>
<ns0:EndorsementReference>0</ns0:EndorsementReference>
<ns0:EndorsementName></ns0:EndorsementName>
<ns0:Description></ns0:Description>
<ns0:EffectiveDate></ns0:EffectiveDate>
</ns0:Endorsement>
<ns0:ContractSection ContractReportingLevel="section_level">
<ns0:HighLevelReference>01</ns0:HighLevelReference>
<ns0:CoverType>quota_share</ns0:CoverType>
<ns0:ContractPeriod>
<ns0:StartDate DateIndicator="Jan 1 2013 12:00AM"></ns0:StartDate>
<ns0:EndDate DateIndicator="Dec 31 2013 12:00AM"></ns0:EndDate>
</ns0:ContractPeriod>
<ns0:UnderwritingYear>Jan </ns0:UnderwritingYear>
<ns0:ContractSectionClass>
<ns0:JvClassOfBusiness>wind_storm_unspecified</ns0:JvClassOfBusiness>
<ns0:ClassOfBusinessDescription>wind_storm_unspecified</ns0:ClassOfBusinessDescription>
</ns0:ContractSectionClass>
<ns0:RiskLocation>
<ns0:Address>
<ns0:Country></ns0:Country>
</ns0:Address>
<ns0:Location>
<ns0:Supraentity></ns0:Supraentity>
<ns0:Country>BS</ns0:Country>
</ns0:Location>
</ns0:RiskLocation>
<ns0:PerilsIncluded>
<ns0:Peril>
<ns0:PerilType></ns0:PerilType>
</ns0:Peril>
</ns0:PerilsIncluded>
<ns0:ContractAmountsCurrency>
<ns0:Ccy>GBP</ns0:Ccy>
</ns0:ContractAmountsCurrency>
<ns0:BrokerSharePercentage>
<ns0:Rate RateUnit="percentage">2.500000</ns0:Rate>
</ns0:BrokerSharePercentage>
<ns0:OrderPercentage>
<ns0:Rate RateUnit="percentage">41.000000</ns0:Rate>
</ns0:OrderPercentage>
<ns0:Brokerage>
<ns0:BrokeragePercentage>
<ns0:Rate RateUnit="percentage">2.500000</ns0:Rate>
</ns0:BrokeragePercentage>
</ns0:Brokerage>
<ns0:ContractMarket>
<ns0:Reinsurer>
<ns0:Party>
<ns0:Id Agency="DUNS_dun_and_bradstreet">239195295</ns0:Id>
</ns0:Party>
</ns0:Reinsurer>
<ns0:ParticipantFunction>leader</ns0:ParticipantFunction>
<ns0:ReinsurerContractReference></ns0:ReinsurerContractReference>
<ns0:ReinsurerQuoteMaximumSharePercentage>
<ns0:Rate RateUnit="percentage">100.000000</ns0:Rate>
</ns0:ReinsurerQuoteMaximumSharePercentage>
<ns0:ReinsurerWrittenPercentage>
<ns0:Rate RateUnit="percentage">100.000000</ns0:Rate>
</ns0:ReinsurerWrittenPercentage>
</ns0:ContractMarket>
</ns0:ContractSection>
</ns0:Placing>
</ns0:Root>
XML輸出:
<ns0:Root xmlns:ns0="http://somenamespace">
<ns0:Placing Sender="broker" Receiver="serviceprovider">
<ns0:UUId>GUID</ns0:UUId>
<ns0:BrokerReference>2B3B8992-3185-48EE-A030-0F61EFF7C7EB</ns0:BrokerReference>
<ns0:ServiceProviderReference>16</ns0:ServiceProviderReference>
<ns0:PlacingStage>order</ns0:PlacingStage>
<ns0:PlacingTransactionFunction>signed_line_advice</ns0:PlacingTransactionFunction>
<ns0:TransactionReasonDescription />
<ns0:Cedent>
<ns0:Party>
<ns0:Id Agency="DUNS_dun_and_bradstreet">292320710</ns0:Id>
<ns0:Name>Bahamas First General Insurance Co/Aon Benfield Canada</ns0:Name>
</ns0:Party>
</ns0:Cedent>
<ns0:Broker>
<ns0:Party>
<ns0:Id Agency="DUNS_dun_and_bradstreet">292320710</ns0:Id>
<ns0:Name>Aon Benfield UK</ns0:Name>
</ns0:Party>
<ns0:Contact>
<ns0:PersonName>Jenny Edwards</ns0:PersonName>
<ns0:Telephone>reinsurance_contract</ns0:Telephone>
<ns0:Email>[email protected]</ns0:Email>
</ns0:Contact>
</ns0:Broker>
<ns0:ServiceProvider>
<ns0:Party>
<ns0:Id Agency="DUNS_dun_and_bradstreet">239195295</ns0:Id>
</ns0:Party>
</ns0:ServiceProvider>
<ns0:Contract>
<ns0:ContractName>FINCO QUOTA SHARE TREATY</ns0:ContractName>
<ns0:ContractGroupName>BFG FINCO QUOTA SHARE TREATY</ns0:ContractGroupName>
<ns0:ContractType>0</ns0:ContractType>
<ns0:BrokerReference>B110813BDO1053</ns0:BrokerReference>
<ns0:BrokerGroupReference>200153436</ns0:BrokerGroupReference>
<ns0:BrokerRiskReference>13BDO1053</ns0:BrokerRiskReference>
</ns0:Contract>
<ns0:Endorsement>
<ns0:EndorsementReference>0</ns0:EndorsementReference>
</ns0:Endorsement>
<ns0:ContractSection ContractReportingLevel="section_level">
<ns0:HighLevelReference>01</ns0:HighLevelReference>
<ns0:CoverType>quota_share</ns0:CoverType>
<ns0:ContractPeriod>
<ns0:StartDate DateIndicator="Jan 1 2013 12:00AM" />
<ns0:EndDate DateIndicator="Dec 31 2013 12:00AM" />
</ns0:ContractPeriod>
<ns0:UnderwritingYear>Jan </ns0:UnderwritingYear>
<ns0:ContractSectionClass>
<ns0:JvClassOfBusiness>wind_storm_unspecified</ns0:JvClassOfBusiness>
<ns0:ClassOfBusinessDescription>wind_storm_unspecified</ns0:ClassOfBusinessDescription>
</ns0:ContractSectionClass>
<ns0:RiskLocation>
<ns0:Address>
<ns0:Country />
</ns0:Address>
<ns0:Location>
<ns0:Country>BS</ns0:Country>
</ns0:Location>
</ns0:RiskLocation>
<ns0:ContractAmountsCurrency>
<ns0:Ccy>GBP</ns0:Ccy>
</ns0:ContractAmountsCurrency>
<ns0:BrokerSharePercentage>
<ns0:Rate RateUnit="percentage">2.500000</ns0:Rate>
</ns0:BrokerSharePercentage>
<ns0:OrderPercentage>
<ns0:Rate RateUnit="percentage">41.000000</ns0:Rate>
</ns0:OrderPercentage>
<ns0:LinesPercentageOfOrderIndicator>false</ns0:LinesPercentageOfOrderIndicator>
<ns0:Brokerage>
<ns0:BrokeragePercentage>
<ns0:Rate RateUnit="percentage">2.500000</ns0:Rate>
</ns0:BrokeragePercentage>
</ns0:Brokerage>
<ns0:ContractMarket>
<ns0:Reinsurer>
<ns0:Party>
<ns0:Id Agency="DUNS_dun_and_bradstreet">239195295</ns0:Id>
</ns0:Party>
</ns0:Reinsurer>
<ns0:ParticipantFunction>leader</ns0:ParticipantFunction>
<ns0:ReinsurerQuoteMaximumSharePercentage>
<ns0:Rate RateUnit="percentage">100.000000</ns0:Rate>
</ns0:ReinsurerQuoteMaximumSharePercentage>
<ns0:ReinsurerWrittenPercentage>
<ns0:Rate RateUnit="percentage">100.000000</ns0:Rate>
</ns0:ReinsurerWrittenPercentage>
</ns0:ContractMarket>
</ns0:ContractSection>
</ns0:Placing>
</ns0:Root>
我遇到的問題是與節點 它應屬於<ns0:ContractSection>
下,代替它的是來到的父節點下這是<ns0:Placing>
請編輯問題並提供一個完整的(但很小的)源XML文檔。還提供一個完整的轉換(如果可能,小)。在目前的狀態下,這不是一個真正的問題。 – 2013-05-12 23:17:13
@DimitreNovatchev好的。對於疏忽感到抱歉。我已經添加了樣式表和一個示例xml。讓我知道。謝謝 – JohnXsl 2013-05-13 00:40:34
請澄清:這是*「XML輸出」*你*要求*,或者它是你目前得到的需要修復? – Borodin 2013-05-13 15:31:11