Hitzz91
Hitzz91

Reputation: 39

How to remove xml nodes which start with Name as Format

I am trying to removing certain nodes which start with "Format" from the input. I have removed some nodes by specifying the names directly but there are a lot of nodes which start with "Format". Could any one direct me how can I remove the nodes with "Format" at start. Here is my XML

<PolicyHdr>
  <PolicyHdrData>
    <PolicyHdrData>
      <ChangeType>-1</ChangeType>
      <CoreMessageObjectArray>
        <HasMessage>False</HasMessage>
        <Message />
        <MessageCode />
        <Severity>0</Severity>
      </CoreMessageObjectArray>
      <ID>c1be84b1-f081-4fa6-bb45-610adc176042</ID>
      <PolicyPrefix />
      <PolicyNumber>TSAZ00001019</PolicyNumber>
      <DTCCDistTrxIDNum />
      <Status id="00000000-0000-0000-0000-000000000004" code="22">Active</Status>
      <IssueState id="00000000-0000-0000-0000-000000000006" code="OLI_USA_CA">California</IssueState>
      <IssueCountry id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <AppReceivedDate>2016-09-12T08:55:28.0000000</AppReceivedDate>
      <ApplicationDate>2016-09-12T00:00:00.0000000</ApplicationDate>
      <Qualified id="0">False</Qualified>
      <ProdModelID id="7a841184-484b-457d-8a24-8257984dc5f0" code="Paycheck_Term">Lifely Term</ProdModelID>
      <LOB id="00000000-0000-0000-0000-000000000003" code="L">Traditional Life</LOB>
      <CompanyID id="00000000-0000-0000-0000-000000000020" code="PLAZ">Pruco Life of AZ</CompanyID>
      <ExchangeType id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <HasPendingTrx id="1">True</HasPendingTrx>
      <PolicyEffDate>2016-09-12T00:00:00.0000000</PolicyEffDate>
      <TamraTestInd id="0">False</TamraTestInd>
      <IRC7702Test>CVAT</IRC7702Test>
      <TSA id="0">False</TSA>
      <CommOptionType id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <CommIntRateType id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <FixedIndexedMode id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <ModeRule>0</ModeRule>
      <QualifiedCode id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <OriginalPolicyNumber />
      <CertificateSuffix />
      <ResidentState id="00000000-0000-0000-0000-000000000006" code="OLI_USA_CA">California</ResidentState>
      <ExchangeFlag id="0">False</ExchangeFlag>
      <BrokerageAccount />
      <MarketSegment id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <SpecialMarket id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <ContributorType id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <PolicySwitch id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <PlanOption>CP15</PlanOption>
      <PreventMEC id="0">False</PreventMEC>
      <AppSignCity />
      <AppSignState id="00000000-0000-0000-0000-000000000006" code="OLI_USA_CA">California</AppSignState>
      <MembershipNum />
      <AnnuityType />
      <AgentMatching id="0">False</AgentMatching>
      <SystematicWithdrawal id="0">False</SystematicWithdrawal>
      <SpecialRequest />
      <TIA90Days id="0">False</TIA90Days>
      <TIA2Years id="0">False</TIA2Years>
      <CashOnHand>0</CashOnHand>
      <EstimatedTransferAmount>0</EstimatedTransferAmount>
      <FreeLookPeriod>0</FreeLookPeriod>
      <AppType id="00000000-0000-0000-0000-000000000004" code="EAPP">E-App</AppType>
      <ReplacementPercent>1</ReplacementPercent>
      <ModeOfSettlement id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <ExchangeBasis1035>0</ExchangeBasis1035>
      <ExchangePrem1035Ext>0</ExchangePrem1035Ext>
      <ExchangePrem1035Int>0</ExchangePrem1035Int>
      <PriorMECStatus id="ffffffff-ffff-ffff-ffff-ffffffffffff" code="" />
      <RateLockEffectiveDate>1900-01-01T00:00:00.0000000</RateLockEffectiveDate>
      <ProductCUSIP />
      <FreeLookEndDate>2016-10-12T00:00:00.0000000</FreeLookEndDate>
      <FreeLookStartDate>2017-08-23T00:00:00.0000000</FreeLookStartDate>
      <ReplacementFlag id="0">False</ReplacementFlag>
      <EntityStatus id="0">False</EntityStatus>
      <DisplayFieldName>TSAZ00001019,9/12/2016 12:00:00 AMActiveCalifornia</DisplayFieldName>
      <UserID>cb177837-37c0-4033-88d9-a40853a2a342</UserID>
      <TimeStamp>2017-08-23T16:28:12.2030000</TimeStamp>
      <FormatCashOnHand>$0.00</FormatCashOnHand>
      <FormatEstimatedTransferAmount>$0.00</FormatEstimatedTransferAmount>
    </PolicyHdrData>
  </PolicyHdrData>
</PolicyHdr>

and Here is XSLT which I have written

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>
<xsl:template match="CoreMessageObjectArray[not(*/term[string-length()>0])]"/>
<xsl:template match="ChangeType[not(*/term[string-length()>0])]"/>
<xsl:template match="EntityStatus[not(*/term[string-length()>0])]"/>
<xsl:template match="ID[not(*/term[string-length()>0])]"/>
<xsl:template match="DisplayName[not(*/term[string-length()>0])]"/>
<xsl:template match="UserID[not(*/term[string-length()>0])]"/>
<xsl:template match="Sequence[not(*/term[string-length()>0])]"/>
</xsl:stylesheet>

Upvotes: 1

Views: 38

Answers (1)

Tim C
Tim C

Reputation: 70638

If you want to remove all elements whose name starts with "Format" just add this template

<xsl:template match="*[starts-with(local-name(), 'Format')]"/>

Upvotes: 1

Related Questions