Subject: Re: [xsl] Transform selected attribute to element when element already has a value | XSLT 2.0 From: "Sam Spade anonymousjuly1@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 22 May 2021 00:01:47 -0000 |
2.B B B B As I point out in the post, B https://stackoverflow.com/questions/67575484/what-attribute-node-cannot-follo w-non-attribute-node-in-element-content-tells B it is not only very difficult to search value if anelement (<currency>) contains both element (<id>) and text value(USD) but alsoreturns false result. B B B B B B B B B B B B B B B <amount> B B B B B B B B B B B B B B B B B <currency> B B B B B B B B B B B B B B B B B B B B <id>settlementCurrency</id>USD</currency> B B B B B B B B B B B B B B B B B <referenceAmount>StandardISDA</referenceAmount> B B B B B B B B B B B B B B B B B <cashSettlement>true</cashSettlement> B B B B B B B B B B B B B B </amount> B That USD really is the value of <currency>. In this case, it is legitimate andsensible to transform id as sibling element of its originalelement <currency> (its parent is still <amount>) to: B <amount> B B B <currency>USD</currency> B B B <id>settlementCurrency</id> B B B <referenceAmount>StandardISDA</referenceAmount> B B B <cashSettlement>true</cashSettlement> </amount> The flattened XML is very searchable (an index on 'currency' is good enough) and can be transformed to JSON. On Friday, May 21, 2021, 10:35:53 a.m. MST, Martin Honnen martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: On 21.05.2021 16:30, Sam Spade anonymousjuly1@xxxxxxxx wrote: > |The transformation logic: > ||| > > | > 1) transform namespace > > 2) transform root element > > 3) transform the selected attribute(s) to element (the attribute name is > parameterised not hard-coded) > > 4) the transformed element shouldn't contain both other element > (transformed from the attribute) and its original data > | > > | > The desired result: > > |<requestProduct xmlns="http://fc.fasset/product"> <trade> <cal> > <c>PRECEDING</c> <bcs> <id>businessCenters</id> <bc>USNY</bc> > <bc>GBLO</bc> </bcs> </cal> <amount> *<currency>USD</currency> > <id>settlementCurrency</id>* > <referenceAmount>StandardISDA</referenceAmount> > <cashSettlement>true</cashSettlement> </amount> </trade> </requestProduct>| > > What is wrong with my module? How can I transform the input to the > desired result? | What is the criteria to transform an attribute to a child element of its parent as is done for the "id" of the "bcs" element and what is the criteria for the other choice, to not include the new element as a child but to make it a sibling of the (previous) parent element?
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Transform selected attrib, Sam Spade anonymousj | Thread | Re: [xsl] Transform selected attrib, Martin Honnen martin |
Re: [xsl] Transform selected attrib, Sam Spade anonymousj | Date | Re: [xsl] Transform selected attrib, Martin Honnen martin |
Month |