XSLT adding new element to current node -
i have xml , trying add new element assign value on conditions. working fine. however, seems adding new element parent node. can me figure out issue.
below full xslt. having problem last template.
<?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" exclude-result-prefixes="msxsl" xmlns:ns0="http://somenamespace"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="node() | @*"> <xsl:copy> <xsl:apply-templates select="node() | @*" /> </xsl:copy> </xsl:template> <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 != '') , not(ns0:reinsurer/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[not(node())]" /> <xsl:template match="ns0:serviceprovider[. = '6']" /> <xsl:template match="ns0:serviceprovider[not(ns0:party/ns0:id != '') , not(ns0:reinsurer/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()) , 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:contractsection/ns0:brokerage[descendant::ns0:rate = '' , not(ns0:contractsection/ns0:brokeragepercentage/ns0:rate > 0)]" /> <xsl:template match="ns0:contractsection/ns0:contractmarket/ns0:reinsurer[descendant::ns0:id = '' , 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 = '' , ns0:placingtransactionfunction = 'signed_line_advice']" /> <xsl:template match="ns0:placing"> <xsl:variable name="percentage-rate" select="ns0:contractsection/ns0:orderpercentage/ns0:rate"/> <xsl:copy> <ns0:contractsection> <ns0:linespercentageoforderindicator> <xsl:value-of select="ns0:placingtransactionfunction = 'signed_line_advice' , $percentage-rate > 100"/> </ns0:linespercentageoforderindicator> <xsl:apply-templates select="ns0:contractsection/ns0:contractmarket"/> </ns0:contractsection> </xsl:copy> </xsl:template> </xsl:stylesheet>
source xml:
<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>
xml output:
<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:cedent> <ns0:party> <ns0:id agency="duns_dun_and_bradstreet">292320710</ns0:id> <ns0:name>bahamas first general insurance co/aon benfield canada</ns0:name> </ns0:party> </ns0:cedent> <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: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:enddate dateindicator="dec 31 2013 12:00am" /> </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:address> <ns0:location> <ns0:country>bs</ns0:country> </ns0:location> </ns0:risklocation> <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:linespercentageoforderindicator>false</ns0:linespercentageoforderindicator> <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: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>
the problem i'm having <ns0:linespercentageoforderindicator>
node should fall under <ns0:contractsection>
instead coming under parent node of <ns0:contractsection>
<ns0:placing>
this stylesheet seems need, although points unclear.
note string value of boolean expression either true
or false
, since that's want can use value-of
instead of choose
/ when
/ otherwise
have done here. i've pulled out value of order percentage rate variable expression isn't ungainly.
since new linespercentageoforderindicator
element depends on both placingtransactionfunction
, orderpercentage/rate
assume that's why both these original elements missing output, i've coded way. i'm not clear why reinsurercontractreference
element isn't in desired output, , if that's mistake need remove final template matches element , reinstated.
<?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" exclude-result-prefixes="msxsl"> <xsl:strip-space elements="*"/> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="ns0:placing"> <xsl:variable name="percentage-rate" select="ns0:contractsection/ns0:orderpercentage/ns0:rate"/> <xsl:copy> <ns0:contractsection> <ns0:linespercentageoforderindicator> <xsl:value-of select="ns0:placingtransactionfunction = 'signed_line_advice' , $percentage-rate > 100"/> </ns0:linespercentageoforderindicator> <xsl:apply-templates select="ns0:contractsection/ns0:contractmarket"/> </ns0:contractsection> </xsl:copy> </xsl:template> <xsl:template match="ns0:reinsurercontractreference"/> </xsl:stylesheet>
output
<ns0:root xmlns:ns0="http://somenamespace"> <ns0:placing> <ns0:contractsection> <ns0:linespercentageoforderindicator>false</ns0:linespercentageoforderindicator> <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: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>
update
in addition have, need template orderpercentage
adds new linespercentageoforderindicator
after copying itself.
this should trick.
<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' , ns0:rate > 100"/> </ns0:linespercentageoforderindicator> </xsl:template>
i note have numerous ways of checking whether element empty. there is
not(node())
, "has no children"element = ''
evaluates element stringnot(element != '')
same, more confusing!
for latter 2 work need strip insignificant spaces text nodes, either using <xsl:strip-space elements="*"/>
@ top of stylesheet, or using normalize-space
on value in test. neatest use fact expression evaluates false
if empty string, can write not(element)
test if empty.
in addition have these
ns0:reinsurer[not(ns0:party/ns0:id != '') , not(ns0:reinsurer/ns0:party/ns0:id/@agency[. != ''])]
and
ns0:serviceprovider[not(ns0:party/ns0:id != '') , not(ns0:reinsurer/ns0:party/ns0:id/@agency[. != ''])]
which should be
ns0:serviceprovider[not(ns0:party/ns0:id or ns0:party/ns0:id/@agency)]
and
ns0:serviceprovider[not(ns0:party/ns0:id or ns0:party/ns0:id/@agency)]
because nice lose double negatives, , there no ns0:reinsurer
child of either ns0:reinsurer
element or ns0:serviceprovider
element. (it isn't clear data ns0:serviceprovider
can have children @ all, can't sure.)
Comments
Post a Comment