xsl-list
[Top] [All Lists]

Re: [xsl] Transform selected attribute to element when element already has a value | XSLT 2.0

2021-05-21 19:01:17
 
Hi, Martin:

            The purposesof flattening the XML are:

1.    After the $keepAttr is flattened to element (therewill not be any 
attribute ), I can further transform the flattened XML to JSON.That is the 
purpose of this post:

https://stackoverflow.com/questions/67145900/xquery-constructs-string-object-with-sequential-ancestor-node-names
The original <businessCenters> will be transformed to JSON array.
                  <calculationPeriodDatesAdjustments>
                    <businessDayConvention>PRECEDING</businessDayConvention>
                    <businessCenters id="businessCenters">
                      <businessCenter>USNY</businessCenter>
                      <businessCenter>GBLO</businessCenter>
                    </businessCenters>
                  </calculationPeriodDatesAdjustments>

 
It is legitimate to transform id as child element of <businessCenters>. But 
data transformation is not just for convenience,if I transform that id out of 
<businessCenters> as a sibling of <businessDayConvention>.  The context of id  
is completed lost. In asearch engine, index “root/businessCenters/id” vs 
“root/id” returns differentvalue.  


    On Friday, May 21, 2021, 10:35:53 a.m. MST, Martin Honnen 
martin(_dot_)honnen(_at_)gmx(_dot_)de 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:  
 
 On 21.05.2021 16:30, Sam Spade anonymousjuly1(_at_)yahoo(_dot_)ca 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?


  
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>