Question

I have to achieve below.

if <m_control>/<initiator_id> is Dummy then the xml element, <note>/<reason> should be removed.Below is the hirarchy of the note element.

<o:m_content/o:application/o:product/o:client_specific_illustration/o:note>

Below is the sample xml:

<?xml version="1.0"?>
<message xmlns="http://www.origoservices.com"    xmlns:ns2="http://www.w3.org/2000/09/xmldsig#">

 <m_control>
    <expected_response_type>synchronous</expected_response_type>
    <initiator_id>Dummy</initiator_id>
    <user_id>Dummy</user_id>
    <responder_id>Responder</responder_id>
</m_control>
<m_content>
    <b_control>
        <message_version_number>3.7</message_version_number>
        <submission_date>2014-04-14</submission_date>
    </b_control>
<intermediary type="Test">
    <rdr_basis_of_sale>
        <advised_category>Independent</advised_category>
    </rdr_basis_of_sale>
</intermediary>
<application>
    <address id="ADPC2">
        <postcode>AB24 3DB</postcode>
    </address>
    <address id="ADPC1">
        <postcode>B14 7JG</postcode>
    </address>
    <personal_client id="PC1">
        <title>Mr</title>
        <forenames>Test</forenames>
        <surname>FLtwelve</surname>
        <sex>Male</sex>
        <marital_status>Married</marital_status>
        <date_of_birth>1950-10-16</date_of_birth>
        <employment_contract>
            <occupation code="AAB00021">Actuary</occupation>
            <full_time_ind>No</full_time_ind>
        </employment_contract>
        <smoker_ind>No</smoker_ind>
        <residential_status>In Own Home - With Someone Else</residential_status>
        <home_address address_id="ADPC1"/>
        <enhanced_underwriting>
            <medical_conditions/>
        </enhanced_underwriting>
        <tpsdata>
            <postcode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">test</postcode>
        </tpsdata>
    </personal_client>
    <personal_client id="PC2">
        <employment_contract>
            <occupation code="WAB02558">Wig Maker</occupation>
            <full_time_ind>Yes</full_time_ind>
        </employment_contract>
        <smoker_ind>Yes</smoker_ind>
        <residential_status>In Own Home - Alone</residential_status>
        <home_address address_id="ADPC2"/>
        <enhanced_underwriting>
            <medical_conditions/>
            <lifestyle>
                <height units="Centimetre">180</height>
                <weight units="Kilogram">70</weight>
                <waist units="Centimetre">81</waist>
                <units_of_alcohol_per_week>1</units_of_alcohol_per_week>
                <smoking_details>
                    <regular_smoker_ind>Yes</regular_smoker_ind>
                    <current_smoking>
                        <number_of_cigarettes_per_day>4</number_of_cigarettes_per_day>
                        <number_of_cigars_per_day>0</number_of_cigars_per_day>
                        <rolling_tobacco_per_week units="Gram">0</rolling_tobacco_per_week>
                        <pipe_tobacco_per_week units="Gram">0</pipe_tobacco_per_week>
                        <start_date>1985-09</start_date>
                    </current_smoking>
                </smoking_details>
            </lifestyle>
        </enhanced_underwriting>
        <tpsdata>
            <postcode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">AB24 3DB</postcode>
        </tpsdata>
    </personal_client>
    <product type="Compulsory Purchase Annuity" product_code="CPA">
        <open_market_option_ind>Yes</open_market_option_ind>
        <annuity type="Non Protected Rights">
            <annuitant sequence_number="1" personal_client_id="PC1"/>
            <with_profit_ind>No</with_profit_ind>
            <contribution legislation_applicable="Post 1997">
                <amount currency="GBP">391586</amount>
                <source_details>
                    <product_type>Occupational Scheme - Defined Contribution</product_type>
                    <product_provider_name>Other</product_provider_name>
                    <transfer_ind>No</transfer_ind>
                </source_details>
                <adviser_charges_applicable>
                    <adviser_charge_applicable adviser_charge_id="ac1"/>
                </adviser_charges_applicable>
            </contribution>
            <payment_frequency>Annually</payment_frequency>
            <payment_timing_code>In Advance</payment_timing_code>
            <escalation>
                <change_index>Level</change_index>
                <lpi_lag_basis>Statutory</lpi_lag_basis>
                <proportionate_escalation_ind>No</proportionate_escalation_ind>
            </escalation>
            <payment_period>
                <start_basis>Specified Date</start_basis>
                <start_date>2014-04-14</start_date>
            </payment_period>
            <guaranteed_period>
                <years>5</years>
            </guaranteed_period>
            <commuted_ind>No</commuted_ind>
            <with_proportion_ind>No</with_proportion_ind>
            <reversionary_annuity type="Spouse" legislation_applicable="Post 1997">
                <annuitant personal_client_id="PC2"/>
                <number_of_dependants>1</number_of_dependants>
                <fraction_of_original_payment>
                    <numerator>10</numerator>
                    <denominator>10</denominator>
                </fraction_of_original_payment>
                <payment_period>
                    <start_basis>Next Due Date</start_basis>
                </payment_period>
                <overlap_ind>No</overlap_ind>
                <spouse_remarriage_cease_ind>Yes</spouse_remarriage_cease_ind>
            </reversionary_annuity>
        </annuity>
        <adviser_charges>
            <adviser_charge id="ac1">
                <type>Adviser</type>
                <amount currency="GBP">7831.72</amount>
                <facilitated_from>Annuity In Payment</facilitated_from>
                <facilitated_before_product_investment_ind>Yes</facilitated_before_product_investment_ind>
                <payment_frequency>Single</payment_frequency>
                <reason>Initial</reason>
            </adviser_charge>
        </adviser_charges>
        <illustration_basis>
            <annuity_calculation_required>Payment</annuity_calculation_required>
        </illustration_basis>
        <client_specific_illustration>
            <expiry_date>2014-04-28</expiry_date>
            <note>
                <reason>reason for failure is specified over here</reason>
            </note>
            <pension_annuity type="Non Protected Rights">
                <total_amount currency="GBP">18539.33</total_amount>
                <reversionary_annuity>
                    <total_amount currency="GBP">18539.33</total_amount>
                </reversionary_annuity>
            </pension_annuity>
            <adviser_charges>
                <adviser_charge>
                    <adviser_charge_requested adviser_charge_id="ac1"/>
                    <type>Adviser</type>
                    <amount currency="GBP">7831.72</amount>
                    <facilitated_from>Annuity In Payment</facilitated_from>
                    <facilitated_before_product_investment_ind>Yes</facilitated_before_product_investment_ind>
                    <payment_frequency>Single</payment_frequency>
                    <reason>Initial</reason>
                </adviser_charge>
            </adviser_charges>
            <tpsdata>
                <guaranteed_quote>Yes</guaranteed_quote>
            </tpsdata>
        </client_specific_illustration>
    </product>
    <document_out type="Client Specific Illustration">
        <print_requirements>
            <distribution_method>Web Hosted</distribution_method>
            <web_host_format>PDF</web_host_format>
        </print_requirements>
    </document_out>
</application>
</m_content>
</message>

Below is the xslt that I have tried, but I am not getting the expected output as the note/reason element is not getting removed.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   xmlns:o="http://www.origoservices.com" xmlns:dp="http://www.datapower.com/extensions" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:date="http://exslt.org/dates-and-times" version="1.0" extension-element-prefixes="dp" exclude-result-prefixes="fn date">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="o:m_content/o:application/o:product/o:client_specific_illustration/o:note[../../../../../o:m_control/o:initiator_id='TEX']">

  </xsl:template>
</xsl:stylesheet>

Could anyone please let me know, where am I comiting mistake?

Regards.

Was it helpful?

Solution

Just have a variable to store the initiator_id. As below:

<xsl:variable name="test" select="o:message/o:m_control/o:initiator_id"/>

Then, test the note node

<xsl:template match="o:note[parent::o:client_specific_illustration]">
    <xsl:choose>
        <xsl:when test="$test='Dummy'"></xsl:when>
        <xsl:otherwise>
            <xsl:copy>
                <xsl:apply-templates/>
            </xsl:copy>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

The complete stylesheet therefore is:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:o="http://www.origoservices.com" xmlns:dp="http://www.datapower.com/extensions"
    xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:date="http://exslt.org/dates-and-times"
    version="1.0" extension-element-prefixes="dp" exclude-result-prefixes="fn date">

    <xsl:output omit-xml-declaration="yes" indent="yes"/>

    <xsl:strip-space elements="*"/>

    <xsl:output method="xml" indent="yes"/>

    <xsl:variable name="test" select="o:message/o:m_control/o:initiator_id"/>

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

    <xsl:template match="o:note[parent::o:client_specific_illustration]">
        <xsl:choose>
            <xsl:when test="$test='Dummy'"></xsl:when>
            <xsl:otherwise>
                <xsl:copy>
                    <xsl:apply-templates/>
                </xsl:copy>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

as an alternative, you can just use

<xsl:template match="o:m_content[preceding-sibling::o:m_control/o:initiator_id='Dummy']/o:application/o:product/o:client_specific_illustration/o:note"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top