我正在尝试从输出 XML 中重命名/删除命名空间前缀。但是,顶部元素之一应包含不带前缀的命名空间声明。
XSLT 工作不正常。在某些情况下,我仍然可以在输出 XML 中看到命名空间前缀,并且命名空间没有出现在我想要查看的元素中。
我尝试使用 exclude-result-prefixes 和一些模板,但无法正常工作。只是为了澄清我正在使用 XSLT 1.0
提前致谢 ...
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"
xmlns:ns0="http://somenamespace"
xmlns:ac="http://ac.namespace"
exclude-result-prefixes="ns0 msxsl ac">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" encoding="utf-8"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="node()|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<!--<xsl:template match="@*[local-name(.)='ns0']"/>-->
<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 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[.='']" />
<xsl:template match="ns0:ServiceProvider[. = '6']" />
<xsl:template match="ns0:ServiceProvider[not(ns0:Party/ns0:Id and 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:OrderPercentage">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
<ns0:LinesPercentageOfOrderIndicator>
<xsl:value-of select="ancestor::ns0:Placing/ns0:PlacingTransactionFunction = 'signed_line_advice' and ns0:Rate > 100"/>
</ns0:LinesPercentageOfOrderIndicator>
</xsl:template>
<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:stylesheet>
样本输入:
<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>test@ri3k.com</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>jenny.edwards@aonbenfield.com</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>
预期输出:
<Root xmlns="http://somenamespace" xmlns="http://ac.namespace">
<Placing xmlns="http://somenamespace" Sender="broker" Receiver="serviceprovider">
<UUId>GUID</UUId>
<BrokerReference>2B3B8992-3185-48EE-A030-0F61EFF7C7EB</BrokerReference>
<ServiceProviderReference>16</ServiceProviderReference>
<PlacingStage>order</PlacingStage>
<PlacingTransactionFunction>signed_line_advice</PlacingTransactionFunction>
<TransactionReasonDescription />
<Cedent>
<Party>
<Id Agency="DUNS_dun_and_bradstreet" >292320710</Id>
<Name>Bahamas First General Insurance Co/Aon Benfield Canada</Name>
</Party>
</Cedent>
<Reinsurer>
<Party>
<Id Agency="" />
<Name>RI3K</Name>
</Party>
<Contact>
<PersonName>test</PersonName>
<Email>test@ri3k.com</Email>
</Contact>
</Reinsurer>
<Broker>
<Party>
<Id Agency="DUNS_dun_and_bradstreet">292320710</Id>
<Name>Aon Benfield UK</Name>
</Party>
<Contact>
<PersonName>Jenny Edwards</PersonName>
<Telephone>reinsurance_contract</Telephone>
<Email>jenny.edwards@aonbenfield.com</Email>
</Contact>
</Broker>
<ServiceProvider>
<Party>
<Id Agency="DUNS_dun_and_bradstreet">239195295</Id>
</Party>
</ServiceProvider>
<Contract>
<ContractName>FINCO QUOTA SHARE TREATY</ContractName>
<ContractGroupName>BFG FINCO QUOTA SHARE TREATY</ContractGroupName>
<ContractType>0</ContractType>
<BrokerReference>B110813BDO1053</BrokerReference>
<BrokerGroupReference>200153436</BrokerGroupReference>
<BrokerRiskReference>13BDO1053</BrokerRiskReference>
</Contract>
<Endorsement>
<EndorsementReference>0</EndorsementReference>
</Endorsement>
<ContractSection ContractReportingLevel="section_level">
<HighLevelReference>01</HighLevelReference>
<CoverType>quota_share</CoverType>
<ContractPeriod>
<StartDate DateIndicator="Jan 1 2013 12:00AM" />
<EndDate DateIndicator="Dec 31 2013 12:00AM" />
</ContractPeriod>
<UnderwritingYear>Jan </UnderwritingYear>
<ContractSectionClass>
<JvClassOfBusiness>wind_storm_unspecified</JvClassOfBusiness>
<ClassOfBusinessDescription>wind_storm_unspecified</ClassOfBusinessDescription>
</ContractSectionClass>
<RiskLocation>
<Address>
<Country />
</Address>
<Location>
<Country>BS</Country>
</Location>
</RiskLocation>
<ContractAmountsCurrency>
<Ccy>GBP</Ccy>
</ContractAmountsCurrency>
<BrokerSharePercentage>
<Rate RateUnit="percentage">2.500000</Rate>
</BrokerSharePercentage>
<OrderPercentage >
<Rate RateUnit="percentage">41.000000</Rate>
</OrderPercentage>
<LinesPercentageOfOrderIndicator>false</LinesPercentageOfOrderIndicator>
<Brokerage>
<BrokeragePercentage>
<Rate RateUnit="percentage">2.500000</Rate>
</BrokeragePercentage>
</Brokerage>
<ContractMarket>
<Reinsurer>
<Party>
<Id Agency="DUNS_dun_and_bradstreet">239195295</Id>
</Party>
</Reinsurer>
<ParticipantFunction>leader</ParticipantFunction>
<ReinsurerQuoteMaximumSharePercentage>
<Rate RateUnit="percentage">100.000000</Rate>
</ReinsurerQuoteMaximumSharePercentage>
<ReinsurerWrittenPercentage>
<Rate RateUnit="percentage">100.000000</Rate>
</ReinsurerWrittenPercentage>
</ContractMarket>
</ContractSection>
</Placing>
</Root>