I need to change the namespace from http://tempuri.org/ to http://sergio/service/teste
Following is the input XML:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:RecuperarCopiaResponse xmlns:ns0="http://tempuri.org/">
<ns0:RecuperarCopiaResult><![CDATA[<Abastecimento_NF ULTIMO_PONTEIRO="447050"><Abastecimento_NFRow><DT_PROCESS>6/2/2018 1:46:08</DT_PROCESS><CD_ABASTECIMENTO>123936138</CD_ABASTECIMENTO><CD_VEICULO>479077</CD_VEICULO><CD_TIPO_REGISTRO>1</CD_TIPO_REGISTRO><NR_BANCO>237</NR_BANCO><CD_REDE>801</CD_REDE><DC_REDE>801</DC_REDE><COD_POSTO>244</COD_POSTO><COD_FROTA>4941</COD_FROTA><COD_SUBFROTA>11264</COD_SUBFROTA><DC_SUBFROTA>R2C</DC_SUBFROTA><CD_COMBUSTIVEL>S</CD_COMBUSTIVEL><DC_COMBUSTIVEL>S</DC_COMBUSTIVEL><NR_UVE></NR_UVE><DC_PLACA>KWG8687</DC_PLACA><NM_MOTORISTA></NM_MOTORISTA><NR_KM_ATUAL>226076</NR_KM_ATUAL><NR_QTD_LITROS>139,55</NR_QTD_LITROS><VL_PRECO_UNITARIO>3,798</VL_PRECO_UNITARIO><VL_PRECO_AEP>3,798</VL_PRECO_AEP><VL_VALOR_TOTAL>530,01</VL_VALOR_TOTAL><DT_EVENTO>5/2/2018 14:37:00</DT_EVENTO><DT_DEBITO>26/2/2018 0:00:00</DT_DEBITO><DT_CREDITO>27/2/2018 0:00:00</DT_CREDITO><NOMEARQ>T2060218.ZZ001305.00244</NOMEARQ><NR_KM_PERCORRIDA>365</NR_KM_PERCORRIDA><NR_QTD_LITROS_TOTAL>139,55</NR_QTD_LITROS_TOTAL><CD_STATUS_ABASTECIMENTO>S</CD_STATUS_ABASTECIMENTO><DC_STATUS_ABASTECIMENTO>TOTAL</DC_STATUS_ABASTECIMENTO><DC_NOME_FANTASIA>POSTO DE COMB. CONTORNO DE CAMPOS LTDA</DC_NOME_FANTASIA><DC_CIDADE_COR>CAMPOS DOS GOYTACAZES</DC_CIDADE_COR><NR_CNPJ>31212889000102</NR_CNPJ><PONTEIRO>447050</PONTEIRO><DAT_PROCESSAMENTO_NF>8/2/2018 9:48:05</DAT_PROCESSAMENTO_NF><DSC_NUMERO_NOTA_FISCAL>7507</DSC_NUMERO_NOTA_FISCAL><DSC_CHAVE></DSC_CHAVE><DSC_SERIE></DSC_SERIE></Abastecimento_NFRow></Abastecimento_NF>]]>
</ns0:RecuperarCopiaResult>
</ns0:RecuperarCopiaResponse>
I am using the following xslt code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="enablon">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns0:*">
<xsl:element name="ns0:{local-name()}"
namespace="http://www.supergasbras.com.br/service/CtfAbastecimento">
<xsl:apply-templates select="#*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
Using this XSLT code, I am getting the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:RecuperarCopiaResponse xmlns:ns0="http://tempuri.org/">
<ns0:RecuperarCopiaResult>
<Abastecimento_NF ULTIMO_PONTEIRO="447050">
<Abastecimento_NFRow>
<DT_PROCESS>6/2/2018 1:46:08</DT_PROCESS>
<CD_ABASTECIMENTO>123936138</CD_ABASTECIMENTO>
<CD_VEICULO>479077</CD_VEICULO>
<CD_TIPO_REGISTRO>1</CD_TIPO_REGISTRO>
<NR_BANCO>237</NR_BANCO>
<CD_REDE>801</CD_REDE>
<DC_REDE>801</DC_REDE>
<COD_POSTO>244</COD_POSTO>
<COD_FROTA>4941</COD_FROTA>
<COD_SUBFROTA>11264</COD_SUBFROTA>
<DC_SUBFROTA>R2C</DC_SUBFROTA>
<CD_COMBUSTIVEL>S</CD_COMBUSTIVEL>
<DC_COMBUSTIVEL>S</DC_COMBUSTIVEL>
<NR_UVE/>
<DC_PLACA>KWG8687</DC_PLACA>
<NM_MOTORISTA/>
<NR_KM_ATUAL>226076</NR_KM_ATUAL>
<NR_QTD_LITROS>139,55</NR_QTD_LITROS>
<VL_PRECO_UNITARIO>3,798</VL_PRECO_UNITARIO>
<VL_PRECO_AEP>3,798</VL_PRECO_AEP>
<VL_VALOR_TOTAL>530,01</VL_VALOR_TOTAL>
<DT_EVENTO>5/2/2018 14:37:00</DT_EVENTO>
<DT_DEBITO>26/2/2018 0:00:00</DT_DEBITO>
<DT_CREDITO>27/2/2018 0:00:00</DT_CREDITO>
<NOMEARQ>T2060218.ZZ001305.00244</NOMEARQ>
<NR_KM_PERCORRIDA>365</NR_KM_PERCORRIDA>
<NR_QTD_LITROS_TOTAL>139,55</NR_QTD_LITROS_TOTAL>
<CD_STATUS_ABASTECIMENTO>S</CD_STATUS_ABASTECIMENTO>
<DC_STATUS_ABASTECIMENTO>TOTAL</DC_STATUS_ABASTECIMENTO>
<DC_NOME_FANTASIA>POSTO DE COMB. CONTORNO DE CAMPOS LTDA</DC_NOME_FANTASIA>
<DC_CIDADE_COR>CAMPOS DOS GOYTACAZES</DC_CIDADE_COR>
<NR_CNPJ>31212889000102</NR_CNPJ>
<PONTEIRO>447050</PONTEIRO>
<DAT_PROCESSAMENTO_NF>8/2/2018 9:48:05</DAT_PROCESSAMENTO_NF>
<DSC_NUMERO_NOTA_FISCAL>7507</DSC_NUMERO_NOTA_FISCAL>
<DSC_CHAVE/>
<DSC_SERIE/>
</Abastecimento_NFRow>
</Abastecimento_NF>
</ns0:RecuperarCopiaResult>
Following is the expected XML:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:RecuperarCopiaResponse xmlns:ns0="http://sergio/service/teste">
<ns0:RecuperarCopiaResult>
<Abastecimento_NF ULTIMO_PONTEIRO="447050">
<Abastecimento_NFRow>
<DT_PROCESS>6/2/2018 1:46:08</DT_PROCESS>
<CD_ABASTECIMENTO>123936138</CD_ABASTECIMENTO>
<CD_VEICULO>479077</CD_VEICULO>
<CD_TIPO_REGISTRO>1</CD_TIPO_REGISTRO>
<NR_BANCO>237</NR_BANCO>
<CD_REDE>801</CD_REDE>
<DC_REDE>801</DC_REDE>
<COD_POSTO>244</COD_POSTO>
<COD_FROTA>4941</COD_FROTA>
<COD_SUBFROTA>11264</COD_SUBFROTA>
<DC_SUBFROTA>R2C</DC_SUBFROTA>
<CD_COMBUSTIVEL>S</CD_COMBUSTIVEL>
<DC_COMBUSTIVEL>S</DC_COMBUSTIVEL>
<NR_UVE/>
<DC_PLACA>KWG8687</DC_PLACA>
<NM_MOTORISTA/>
<NR_KM_ATUAL>226076</NR_KM_ATUAL>
<NR_QTD_LITROS>139,55</NR_QTD_LITROS>
<VL_PRECO_UNITARIO>3,798</VL_PRECO_UNITARIO>
<VL_PRECO_AEP>3,798</VL_PRECO_AEP>
<VL_VALOR_TOTAL>530,01</VL_VALOR_TOTAL>
<DT_EVENTO>5/2/2018 14:37:00</DT_EVENTO>
<DT_DEBITO>26/2/2018 0:00:00</DT_DEBITO>
<DT_CREDITO>27/2/2018 0:00:00</DT_CREDITO>
<NOMEARQ>T2060218.ZZ001305.00244</NOMEARQ>
<NR_KM_PERCORRIDA>365</NR_KM_PERCORRIDA>
<NR_QTD_LITROS_TOTAL>139,55</NR_QTD_LITROS_TOTAL>
<CD_STATUS_ABASTECIMENTO>S</CD_STATUS_ABASTECIMENTO>
<DC_STATUS_ABASTECIMENTO>TOTAL</DC_STATUS_ABASTECIMENTO>
<DC_NOME_FANTASIA>POSTO DE COMB. CONTORNO DE CAMPOS
LTDA</DC_NOME_FANTASIA>
<DC_CIDADE_COR>CAMPOS DOS GOYTACAZES</DC_CIDADE_COR>
<NR_CNPJ>31212889000102</NR_CNPJ>
<PONTEIRO>447050</PONTEIRO>
<DAT_PROCESSAMENTO_NF>8/2/2018 9:48:05</DAT_PROCESSAMENTO_NF>
<DSC_NUMERO_NOTA_FISCAL>7507</DSC_NUMERO_NOTA_FISCAL>
<DSC_CHAVE/>
<DSC_SERIE/>
</Abastecimento_NFRow>
</Abastecimento_NF>
</ns0:RecuperarCopiaResult>
</ns0:RecuperarCopiaResponse>
Regards,
Sérgio Salomão
Related
Given the XML code:
<?xml version="1.0" encoding="utf-8"?>
<autoverleih>
<kunden>
<kunde id="p1">
<name nachname="Mustermann" vorname="Mario"/>
<versicherung name="super1" kasko="true"/>
</kunde>
<kunde id="p4">
<name nachname="Gans" vorname="Maria"/>
<versicherung name="die-beste" kasko="false"/>
</kunde>
<kunde id="p54">
<name nachname="Gans" vorname="Gustav"/>
<versicherung name="super1" kasko="false"/>
</kunde>
</kunden>
<ausleihen>
<vertrag kunde="p1" wert="1521.07" datum="2014-07-02" bezahlt="true"/>
<vertrag kunde="p4" wert="397.96" datum="2014-07-12" bezahlt="false"/>
<vertrag kunde="p1" wert="51.23" datum="2014-06-13" bezahlt="true"/>
<vertrag kunde="p54" wert="127.12" datum="2014-08-01" bezahlt="false"/>
</ausleihen>
</autoverleih>
And the following XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform". version="2.0">
<xsl:template match=”autoverleih">
<xsl:value-of select="./kunden/kunde/#id”>
</xsl:template>
<xsl:template match=”vertrag”>
<xsl:value-of select=”../kunde”/>
<xsl:value-of select=”./wert”/>
</xsl:template>
</xsl:stylesheet>
I need to change this code so that for each kunde it only outputs its Id and the wert attribute.
If you want to reference vertrag from kunde I think you can use a key:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">
<xsl:output method="text"/>
<xsl:key name="vertrag-des-kunden" match="vertrag" use="#kunde"/>
<xsl:template match="/">
<xsl:value-of
select="//kunde/#id/concat(., ': ', string-join(key('vertrag-des-kunden', .)/#wert, ', '))"
separator="
"/>
</xsl:template>
</xsl:stylesheet>
https://xsltfiddle.liberty-development.net/a9HjZU
Is there possible after transform & to amp; in comment NodeMy XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<name>ABCD</name>
<!--<querycontent><query-number>AQ1:A (Klumin & Koloskov 1982, Lucas 1977, McMurtry 1974, Patrick & Monahan 1957, Plante 1973, Scherer & Cantelon 2013)</query-number></querycontent>-->
</root>
My XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml" omit-xml-declaration="no"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="comment()">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
I want to output:
<?xml version="1.0" encoding="UTF-8"?><root>
<name>ABCD</name>
<querycontent><query-number>AQ1:A (Klumin & Koloskov 1982, Lucas 1977, McMurtry 1974, Patrick & Monahan 1957, Plante 1973, Scherer & Cantelon 2013)</query-number></querycontent>
</root>
If I am convert XML then only change comment node no entity change.my output is:
<?xml version="1.0" encoding="UTF-8"?><root>
<name>ABCD</name>
<querycontent><query-number>AQ1:A (Klumin & Koloskov 1982, Lucas 1977, McMurtry 1974, Patrick & Monahan 1957, Plante 1973, Scherer & Cantelon 2013)</query-number></querycontent>
</root>
You could change:
<xsl:value-of select="." disable-output-escaping="yes"/>
to:
<xsl:value-of select="replace(., '&', '&')" disable-output-escaping="yes"/>
But this is just slapping another hack on top of the other two. The real problem here is that the content of the comment is not XML.
I am trying to remove Error Description element if it contains empty value using xslt. i tried lot of options but it does not work.
For example if inside Acknowledgement all the element get null then output get empty acknowledgement so I want remove acknowledgement element empty tag.
below is xml and xslt
<?xml version="1.0" encoding="UTF-8" ?>
<updateDocumentStatusResponse xmlns="http://xmlns.be/CommgrService_Message/v001">
<Acknowledgement>
<Result>SUCCESS</Result>
<ErrorCode>ErrorCode1375</ErrorCode>
<ErrorDescription></ErrorDescription>
</Acknowledgement>
</updateDocumentStatusResponse>
XSLT :
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:ns1="http://xmlns.be/CSM/v001" xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction" xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20" xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions" xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator" xmlns:oracle-xsl-mapper="http://www.oracle.com/xsl/mapper/schemas" xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue" xmlns:oraxsl="http://www.oracle.com/XSL/Transform/java" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://xmlns.be/CommgrService_Message/v001" exclude-result-prefixes=" xsd oracle-xsl-mapper xsi xsl ns1 ns0 mhdr oraext xp20 xref socket dvm oraxsl"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<oracle-xsl-mapper:schema>
<oracle-xsl-mapper:mapSources>
<oracle-xsl-mapper:source type="WSDL">
<oracle-xsl-mapper:schema location="../WSDLs/CommgrService_v001.wsdl"/>
<oracle-xsl-mapper:rootElement name="updateDocumentStatusResponse" namespace="http://xmlns.be/CommgrService_Message/v001"/>
</oracle-xsl-mapper:source>
</oracle-xsl-mapper:mapSources>
</oracle-xsl-mapper:schema>
<!--User Editing allowed BELOW this line - DO NOT DELETE THIS LINE-->
<xsl:template match="/">
<ns1:Output>
<ns1:CommunicationResponse>
<ns1:Acknowledgement>
<ns1:Result>
<xsl:value-of select="/ns0:updateDocumentStatusResponse/ns0:Acknowledgement/ns0:Result"/>
</ns1:Result>
<ns1:ErrorCode>
<xsl:value-of select="/ns0:updateDocumentStatusResponse/ns0:Acknowledgement/ns0:ErrorCode"/>
</ns1:ErrorCode>
<ns1:ErrorDescription>
<xsl:value-of select="/ns0:updateDocumentStatusResponse/ns0:Acknowledgement/ns0:ErrorDescription"/>
</ns1:ErrorDescription>
</ns1:Acknowledgement>
</ns1:CommunicationResponse>
</ns1:Output>
</xsl:template>
</xsl:stylesheet>
how can i achieve this?
I think this can be done if you're not thinking something big:
<xsl:if test="normalize-space(/ns0:updateDocumentStatusResponse/ns0:Acknowledgement/ns0:ErrorDescription) != ''">
<ns1:ErrorDescription>
<xsl:value-of select="/ns0:updateDocumentStatusResponse/ns0:Acknowledgement/ns0:ErrorDescription"/>
</ns1:ErrorDescription>
</xsl:if>
Edit:
One way to achieve this using extension function like exsl:node-set or msxsl:node-set to be able to further process a result tree fragment created in another template:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:ns1="http://xmlns.be/CSM/v001" xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction" xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20" xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions" xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator" xmlns:oracle-xsl-mapper="http://www.oracle.com/xsl/mapper/schemas" xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue" xmlns:oraxsl="http://www.oracle.com/XSL/Transform/java" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://xmlns.be/CommgrService_Message/v001" exclude-result-prefixes=" xsd oracle-xsl-mapper xsi xsl ns1 ns0 mhdr oraext xp20 xref socket dvm oraxsl"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<oracle-xsl-mapper:schema>
<oracle-xsl-mapper:mapSources>
<oracle-xsl-mapper:source type="WSDL">
<oracle-xsl-mapper:schema location="../WSDLs/CommgrService_v001.wsdl" />
<oracle-xsl-mapper:rootElement name="updateDocumentStatusResponse" namespace="http://xmlns.be/CommgrService_Message/v001" />
</oracle-xsl-mapper:source>
</oracle-xsl-mapper:mapSources>
</oracle-xsl-mapper:schema>
<!--User Editing allowed BELOW this line - DO NOT DELETE THIS LINE -->
<xsl:template match="/">
<xsl:variable name="result">
<ns1:Output>
<ns1:CommunicationResponse>
<ns1:Acknowledgement>
<ns1:Result>
<xsl:value-of select="/ns0:updateDocumentStatusResponse/ns0:Acknowledgement/ns0:Result" />
</ns1:Result>
<ns1:ErrorCode>
<xsl:value-of select="/ns0:updateDocumentStatusResponse/ns0:Acknowledgement/ns0:ErrorCode" />
</ns1:ErrorCode>
<ns1:ErrorDescription>
<xsl:value-of select="/ns0:updateDocumentStatusResponse/ns0:Acknowledgement/ns0:ErrorDescription" />
</ns1:ErrorDescription>
</ns1:Acknowledgement>
</ns1:CommunicationResponse>
</ns1:Output>
</xsl:variable>
<xsl:apply-templates select="exsl:node-set($result)/*" mode="step2" />
</xsl:template>
<xsl:template match="*[not(normalize-space())]" mode="step2" />
<xsl:template match="#* | node()" mode="step2">
<xsl:copy>
<xsl:apply-templates select="#* | node()" mode="step2" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
http://xsltransform.net/93wkLHW
If you take a top-down aproach with literal result elements you are always going to get that element in the output. Your only choice then is to chain two transformations or use a two pass transformation.
The XPath expression to know whether the current node is empty (true) or not (false) is:
"not(node())"
For example, this input document
<?xml version="1.0" encoding="UTF-8" ?>
<updateDocumentStatusResponse xmlns="http://xmlns.be/CommgrService_Message/v001">
<Acknowledgement>
<Result>SUCCESS</Result>
<ErrorCode>ErrorCode1375</ErrorCode>
<ErrorDescription></ErrorDescription>
</Acknowledgement>
</updateDocumentStatusResponse>
With this transformation
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements ="*"/>
<xsl:output indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(node())]"/>
</xsl:stylesheet>
Output
<updateDocumentStatusResponse xmlns="http://xmlns.be/CommgrService_Message/v001">
<Acknowledgement>
<Result>SUCCESS</Result>
<ErrorCode>ErrorCode1375</ErrorCode>
</Acknowledgement>
</updateDocumentStatusResponse>
Edit
The previus stylesheet is general. If you want to target specific elements, you need to match those elements with the pattern in the template. Example:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements ="*"/>
<xsl:output indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ErrorDescription[not(node())]"/>
</xsl:stylesheet>
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.
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"/>
I am an admitted novice with XSLT and am looking for some direction. I have the follow (simplified) XML input data. I want to take the underlying data and apply it to AccountExternalSystemId or flatten it out.
<?xml version="1.0" ?>
<ns:CustomObject3WS_CustomObject3QueryPage_Output xmlns:ns="urn:crmondemand/ws/customobject3/10/2004">
<ns:LastPage>true</ns:LastPage>
<ListOfCustomObject3 xmlns="urn:/crmondemand/xml/customObject3">
<CustomObject3>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
<ListOfAccount>
<Account>
<AccountId>AAXA-H72YN</AccountId>
<ExternalSystemId>100000000002795</ExternalSystemId>
<Name>CATERPILLAR INC [100000000002795]</Name>
</Account>
<Account>
<AccountId>ADOA-3BAK0F</AccountId>
<ExternalSystemId>A000008351</ExternalSystemId>
<Name>CATERPILLAR</Name>
</Account>
</ListOfAccount>
</CustomObject3>
<CustomObject3>
<AccountExternalSystemId>100000000001059</AccountExternalSystemId>
<ListOfAccount>
<Account>
<AccountId>AAXA-H0B7N</AccountId>
<ExternalSystemId>100000000001059</ExternalSystemId>
<Name>SERV SA [100000000001059]</Name>
</Account>
</ListOfAccount>
</CustomObject3>
</ListOfCustomObject3>
I am applying the following XSL to the data:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="*:CustomObject3WS_CustomObject3QueryPage_Output"/>
</xsl:template>
<xsl:template match="*:CustomObject3WS_CustomObject3QueryPage_Output">
<xsl:copy>
<xsl:apply-templates select="*:LastPage"/>
<xsl:apply-templates select="*:ListOfCustomObject3"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*:ListOfCustomObject3">
<xsl:copy>
<xsl:apply-templates select="*:CustomObject3"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*:CustomObject3">
<xsl:variable select="*:AccountExternalSystemId" name="AccountExternalSystemId"/>
<xsl:copy>
<xsl:for-each select="*:ListOfAccount/*:Account">
<xsl:element name="AccountId" namespace="urn:/crmondemand/xml/customObject3"><xsl:value-of select="substring(*:AccountId,1,15)"/></xsl:element>
<xsl:element name="AccountName" namespace="urn:/crmondemand/xml/customObject3"><xsl:value-of select="substring(*:Name,1,255)"/></xsl:element>
<xsl:element name="AccountExternalSystemId" namespace="urn:/crmondemand/xml/customObject3"><xsl:value-of
select="substring($AccountExternalSystemId,1,64)"/></xsl:element>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
and here is my result (you can see that CustomObject3 is not properly ended (as there should be 2) in the first example. Not sure if my approach is the best way to accomplish what I need to do:
<?xml version="1.0" encoding="UTF-8"?>
<ns:CustomObject3WS_CustomObject3QueryPage_Output>
<ns:LastPage>true</ns:LastPage>
<ListOfCustomObject3 xmlns="urn:/crmondemand/xml/customObject3">
<CustomObject3>
<AccountId>AAXA-H72YN</AccountId>
<AccountName>CATERPILLAR INC [100000000002795]</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
<AccountId>ADOA-3BAK0F</AccountId>
<AccountName>CATERPILLAR</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
</CustomObject3>
<CustomObject3>
<AccountId>AAXA-H0B7N</AccountId>
<AccountName>SERV SA [100000000001059]</AccountName>
<AccountExternalSystemId>100000000001059</AccountExternalSystemId>
</CustomObject3>
</ListOfCustomObject3>
The desired output would be:
<?xml version="1.0" encoding="UTF-8"?>
<ns:CustomObject3WS_CustomObject3QueryPage_Output>
<ns:LastPage>true</ns:LastPage>
<ListOfCustomObject3 xmlns="urn:/crmondemand/xml/customObject3">
<CustomObject3>
<AccountId>AAXA-H72YN</AccountId>
<AccountName>CATERPILLAR INC [100000000002795]</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
</CustomObject3>
<CustomObject3>
<AccountId>ADOA-3BAK0F</AccountId>
<AccountName>CATERPILLAR</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
</CustomObject3>
<CustomObject3>
<AccountId>AAXA-H0B7N</AccountId>
<AccountName>SERV SA [100000000001059]</AccountName>
<AccountExternalSystemId>100000000001059</AccountExternalSystemId>
</CustomObject3>
Remark note that the output in your question presents a prefix (ns:) not bound to any namespace declaration.
Look at this direction:
where identity.xsl is the well known Identity Transformation
default namespaces are handled in a simpler way
produced output has the correct namespace declarations
[XSLT 2.0]
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns="urn:/crmondemand/xml/customObject3"
xpath-default-namespace="urn:/crmondemand/xml/customObject3">
<xsl:output indent="yes"/>
<xsl:include href="identity.xsl"/>
<xsl:template match="CustomObject3">
<xsl:apply-templates select="ListOfAccount/Account"/>
</xsl:template>
<xsl:template match="Account">
<CustomObject3>
<xsl:apply-templates select="AccountId|Name"/>
<xsl:copy-of select="../../AccountExternalSystemId"/>
</CustomObject3>
</xsl:template>
<xsl:template match="Name">
<xsl:element name="Account{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
gives wanted output (with correct namespace declarations):
<ns:CustomObject3WS_CustomObject3QueryPage_Output xmlns:ns="urn:crmondemand/ws/customobject3/10/2004">
<ns:LastPage>true</ns:LastPage>
<ListOfCustomObject3 xmlns="urn:/crmondemand/xml/customObject3">
<CustomObject3>
<AccountId>AAXA-H72YN</AccountId>
<AccountName>CATERPILLAR INC [100000000002795]</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
</CustomObject3>
<CustomObject3>
<AccountId>ADOA-3BAK0F</AccountId>
<AccountName>CATERPILLAR</AccountName>
<AccountExternalSystemId>A000008351</AccountExternalSystemId>
</CustomObject3>
<CustomObject3>
<AccountId>AAXA-H0B7N</AccountId>
<AccountName>SERV SA [100000000001059]</AccountName>
<AccountExternalSystemId>100000000001059</AccountExternalSystemId>
</CustomObject3>
</ListOfCustomObject3>
</ns:CustomObject3WS_CustomObject3QueryPage_Output>