重命名元素的 XSLT 问题——更改命名空间

Posted

技术标签:

【中文标题】重命名元素的 XSLT 问题——更改命名空间【英文标题】:XSLT issue with renaming the elements -- changing namespace 【发布时间】:2013-05-17 03:53:30 【问题描述】:

我正在尝试从输出 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>

【问题讨论】:

这是正确的预期输出吗? Root 没有命名空间,它下面的所有东西都有。我认为您希望 Root 位于同一名称空间中。 @JLRishe:是的,你是对的。我只需要根和放置元素中的命名空间。但是,在 Root 中我需要 2 个,而在孩子(放置)中我只需要一个。我已经更新了预期的输出。 【参考方案1】:

这个 XSLT 做了我认为你实际尝试做的事情(即,将所有内容保留在其原始命名空间中,而不是从中排除 Root):

<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="http://somenamespace"
    xmlns:ac="http://ac.namespace"
    exclude-result-prefixes="ns0 msxsl ac">
  <xsl:strip-space elements="*" />
  <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()" priority="-2">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*" name="CopyElement">
    <xsl:element name="local-name()" namespace="namespace-uri()">
      <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:element name="local-name()" namespace="namespace-uri()">
      <xsl:apply-templates select="@*" />
      <xsl:apply-templates 
           select="../../following-sibling::ns0:Broker[1]/ns0:Party/ns0:Id/node()" />
    </xsl:element>
  </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:call-template name="CopyElement" />
    <LinesPercentageOfOrderIndicator>
      <xsl:value-of select="ancestor::ns0:Placing/ns0:PlacingTransactionFunction = 'signed_line_advice' and ns0:Rate > 100"/>
    </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>

在您的示例输入上运行时,结果是:

<Root xmlns="http://somenamespace">
  <Placing 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>

请告诉我您是否真的想从命名空间中排除 Root

【讨论】:

jlRishe。感谢您的帮助,但它不起作用我仍然在输出中看到命名空间和前缀。例如在输出中我在 Cedent/Party/Id somenamespace"; xmlns:ac=ac.somenamespace">292320710</… First General Insurance Co/Aon Benfield Canada

以上是关于重命名元素的 XSLT 问题——更改命名空间的主要内容,如果未能解决你的问题,请参考以下文章

XSLT 用属性值重命名元素

如何使用 XSLT 替换命名空间中的元素?

xsd:any 元素的命名空间前缀并使用 XSLT 添加命名空间前缀

XSLT 在与根元素具有相同命名空间声明的内部标记中缺少命名空间

XSLT 将命名空间前缀添加到元素最佳实践

使用 xslt 引用具有不同命名空间的元素