2017-05-05 8 views
-1

プログラムからXMLを受け取り、「島」タグを上部と下部に追加してタグを移動し、その子をその親タグの下部に移動したいとします。私のXMLは次のようになります。XSLTを使用して複数の名前空間タグを持つXMLを移動する

XML

<?xml version="1.0"?> 
<IslandPolicyPeriodMessage xmlns="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.period.islandpolicyperiodmessagemodel" xmlns:accountid="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.account.accountidmodel" xmlns:address="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.addressmodel" xmlns:contact="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.contactmodel" xmlns:contactname="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.contactnamemodel" xmlns:coverage="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.coverage.coveragemodel" xmlns:covterm="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.coverage.covtermmodel" xmlns:covtermpattern="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.coverage.covtermpatternmodel" xmlns:form="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.formmodel" xmlns:formtextdata="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.formtextdatamodel" xmlns:gl7cost_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7cost_glemodel" xmlns:gl7coveragepart_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7coveragepart_glemodel" xmlns:gl7covrgpartcoverage_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7covrgpartcoverage_glemodel" xmlns:gl7exposure_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7exposure_glemodel" xmlns:gl7line_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7line_glemodel" xmlns:job="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.job.jobmodel" xmlns:organizationid="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.organizationidmodel" xmlns:policy="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.policymodel" xmlns:policyaddlinsured="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.policyaddlinsuredmodel" xmlns:policyaddlinsureddetail="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.policyaddlinsureddetailmodel" xmlns:policyaddress="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.policyaddressmodel" xmlns:policycontactrole="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.policycontactrolemodel" xmlns:policylocation="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.location.policylocationmodel" xmlns:policyperiod="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.period.policyperiodmodel" xmlns:policyterm="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.policytermmodel" xmlns:producercode="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.producercodemodel" xmlns:renewal="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.job.renewalmodel" xmlns:territorycode="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.general.territorycodemodel" xmlns:userroleassignment="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.userroleassignmentmodel" xmlns:uwcompanyid="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.uwcompanyidmodel"> 
<CertMail_Ext>false</CertMail_Ext> 
<DirectMail_Ext>true</DirectMail_Ext> 
<EventName>SendIssuance</EventName> 
<ImageRightDocumentType_Ext>Renewal Declarations</ImageRightDocumentType_Ext> 
<ImageRightFlowStepID_Ext>3176331764</ImageRightFlowStepID_Ext> 
<ImageRightFolderType_Ext>Print Product</ImageRightFolderType_Ext> 
<JobType>Renewal</JobType> 
<MiscData xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> 
<NonInferredFormCodes xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> 
<PolicyPeriod> 
    <policyperiod:NewlyAddedForms> 
     <Form> 
      <FormName>1</FormName> 
     </Form> 
     <Form> 
      <FormName>2</FormName> 
     </Form> 
    </policyperiod:NewlyAddedForms> 
    <Name>Test</Name> 
</PolicyPeriod> 
</IslandPolicyPeriodMessage> 

XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:i="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.period.islandpolicyperiodmessagemodel" xmlns:accountid="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.account.accountidmodel" xmlns:address="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.addressmodel" xmlns:contact="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.contactmodel" xmlns:contactname="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.contactnamemodel" xmlns:coverage="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.coverage.coveragemodel" xmlns:covterm="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.coverage.covtermmodel" xmlns:covtermpattern="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.coverage.covtermpatternmodel" xmlns:form="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.formmodel" xmlns:formtextdata="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.formtextdatamodel" xmlns:gl7cost_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7cost_glemodel" xmlns:gl7coveragepart_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7coveragepart_glemodel" xmlns:gl7covrgpartcoverage_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7covrgpartcoverage_glemodel" xmlns:gl7exposure_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7exposure_glemodel" xmlns:gl7line_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7line_glemodel" xmlns:job="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.job.jobmodel" xmlns:organizationid="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.organizationidmodel" xmlns:policy="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.policymodel" xmlns:policyaddlinsured="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.policyaddlinsuredmodel" xmlns:policyaddlinsureddetail="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.policyaddlinsureddetailmodel" xmlns:policyaddress="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.policyaddressmodel" xmlns:policycontactrole="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.policycontactrolemodel" xmlns:policylocation="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.location.policylocationmodel" xmlns:policyperiod="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.period.policyperiodmodel" xmlns:policyterm="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.policytermmodel" xmlns:producercode="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.producercodemodel" xmlns:renewal="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.job.renewalmodel" xmlns:territorycode="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.general.territorycodemodel" xmlns:userroleassignment="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.userroleassignmentmodel" xmlns:uwcompanyid="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.uwcompanyidmodel"> 

<xsl:output encoding="UTF-8" indent="yes" method="xml" /> 

<!-- this is the identity transform: it copies everything that isn't matched by a more specific template --> 
<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()" /> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="/i:IslandPolicyPeriodMessage"> 
    <Island> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()" /> 
     </xsl:copy> 
    </Island> 
</xsl:template> 

<xsl:template match="PolicyPeriod" > 
    <xsl:copy> 
     <xsl:apply-templates select="*[not(policyperiod:NewlyAddedForms)]" /> 
     <xsl:apply-templates select="policyperiod:NewlyAddedForms" /> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 

出力

<?xml version="1.0" encoding="UTF-8"?> 
<Island xmlns:i="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.period.islandpolicyperiodmessagemodel" xmlns:accountid="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.account.accountidmodel" xmlns:address="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.addressmodel" xmlns:contact="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.contactmodel" xmlns:contactname="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.contactnamemodel" xmlns:coverage="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.coverage.coveragemodel" xmlns:covterm="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.coverage.covtermmodel" xmlns:covtermpattern="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.coverage.covtermpatternmodel" xmlns:form="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.formmodel" xmlns:formtextdata="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.formtextdatamodel" xmlns:gl7cost_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7cost_glemodel" xmlns:gl7coveragepart_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7coveragepart_glemodel" xmlns:gl7covrgpartcoverage_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7covrgpartcoverage_glemodel" xmlns:gl7exposure_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7exposure_glemodel" xmlns:gl7line_gle="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.line.gl7.gl7line_glemodel" xmlns:job="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.job.jobmodel" xmlns:organizationid="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.organizationidmodel" xmlns:policy="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.policymodel" xmlns:policyaddlinsured="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.policyaddlinsuredmodel" xmlns:policyaddlinsureddetail="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.policyaddlinsureddetailmodel" xmlns:policyaddress="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.policyaddressmodel" xmlns:policycontactrole="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.policycontactrolemodel" xmlns:policylocation="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.location.policylocationmodel" xmlns:policyperiod="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.period.policyperiodmodel" xmlns:policyterm="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.policytermmodel" xmlns:producercode="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.producercodemodel" xmlns:renewal="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.job.renewalmodel" xmlns:territorycode="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.general.territorycodemodel" xmlns:userroleassignment="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.userroleassignmentmodel" xmlns:uwcompanyid="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.contact.uwcompanyidmodel"> 
    <IslandPolicyPeriodMessage xmlns="http://guidewire.com/pc/gx/islandinsurance.pc.gx.exstream.policy.period.islandpolicyperiodmessagemodel"> 
    <CertMail_Ext>false</CertMail_Ext> 
    <DirectMail_Ext>true</DirectMail_Ext> 
    <EventName>SendIssuance</EventName> 
    <ImageRightDocumentType_Ext>Renewal Declarations</ImageRightDocumentType_Ext> 
    <ImageRightFlowStepID_Ext>3176331764</ImageRightFlowStepID_Ext> 
    <ImageRightFolderType_Ext>Print Product</ImageRightFolderType_Ext> 
    <JobType>Renewal</JobType> 
    <MiscData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/> 
    <NonInferredFormCodes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/> 
    <PolicyPeriod> 
     <policyperiod:NewlyAddedForms> 
     <Form> 
      <FormName>1</FormName> 
     </Form> 
     <Form> 
      <FormName>2</FormName> 
     </Form> 
     </policyperiod:NewlyAddedForms> 
    <Name>Test</Name> 
    </PolicyPeriod> 
</IslandPolicyPeriodMessage> 
</Island> 

私の変換作品の最初の部分が、 'policyperiod:NewlyAddedFormsは' ではありません移動した。 「ポリシー期間」の最後のタグになります

ありがとうございます!

答えて

0

PolicyPeriodは、その親からそのネームスペースを継承します。IslandPolicyPeriodMessage。したがって、あなたの:

<xsl:template match="PolicyPeriod" > 

と一致しません。代わりの

<xsl:apply-templates select="*[not(self::policyperiod:NewlyAddedForms)]" /> 

<xsl:apply-templates select="*[not(policyperiod:NewlyAddedForms)]" /> 

注意もそれを

<xsl:template match="i:PolicyPeriod" > 

また、私はあなたが持っているためのものと考えている:あなたはそれを変更する必要があります新しく追加されたIslandルート要素が名前空間にない場合、その子供と異なり、IslandPolicyPeriodMessage。おそらくそれが欲しい結果ですが、私はそれに注意を向ける価値があると思いました。

+0

ありがとうございました!それは '私は:'それを得た。ダング、私はこれを徹底的に取り組んでいて、それは私には起こりませんでした。素晴らしい答え! – Steve

関連する問題