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

"Martin Honnen [email protected]" <[email protected]> Sat, 22 May 2021 08:12:47 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------AA81F6D4BF21FA9DFD9753D6
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable


Am 22.05.2021 um 02:02 schrieb Sam Spade [email protected]:
>
> 2.As I point out in the post,
>
> https://stackoverflow.com/questions/67575484/what-attribute-node-cannot-f=
ollow-non-attribute-node-in-element-content-tells
> <https://stackoverflow.com/questions/67575484/what-attribute-node-cannot-=
follow-non-attribute-node-in-element-content-tells>
>
> it is not only very difficult to search value if an element
> (<currency>) contains both element (<id>) and text value(USD) but also
> returns false result.
>
> <amount>
> <currency>
> <id>settlementCurrency</id>USD</currency>
> <referenceAmount>StandardISDA</referenceAmount>
> <cashSettlement>true</cashSettlement>
> </amount>
>
> That USDreally is the value of<currency>.In this case, it is
> legitimate and sensible to transform idas sibling element of its
> original element <currency>(its parent is still <amount>) to:
>
> <amount>
> <currency>USD</currency>
> <id>settlementCurrency</id>
> <referenceAmount>StandardISDA</referenceAmount>
> <cashSettlement>true</cashSettlement>
> </amount>
>
>
> The flattened XML is very searchable (an index on 'currency' is good
> enough) and can be transformed to JSON.
>
>
>

I am not sure an XSLT program can easily capture your rules but for the
given sample, if you insert a check on elements whether they both have
attributes and non-whitespace text content and in that case transform
any attributes to sibling following the element, the result is as you
wanted:


<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
 =C2=A0 version=3D"3.0"
 =C2=A0 xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
 =C2=A0 exclude-result-prefixes=3D"#all">

 =C2=A0 <xsl:param name=3D"namespace"
as=3D"xs:string">http://fc.fasset/product</xsl:param>

 =C2=A0 <xsl:param name=3D"root" as=3D"xs:string">requestProduct</xsl:param>
 =C2=A0 <xsl:param name=3D"keepAttr" static=3D"yes" as=3D"xs:string*"
select=3D"'href', 'id'"/>

 =C2=A0 <xsl:strip-space elements=3D"*"/>
 =C2=A0 <xsl:output indent=3D"yes"/>

 =C2=A0 <xsl:template match=3D"/*">
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <xsl:element name=3D"{$root}" namespace=3D"=
{$namespace}">
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <xsl:apply-template=
s select=3D"@* , node()"/>
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </xsl:element>
 =C2=A0 </xsl:template>

 =C2=A0 <xsl:template match=3D"*">
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <xsl:element name=3D"{local-name()}" namesp=
ace=3D"{$namespace}">
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <xsl:apply-template=
s select=3D"@* , node()"/>
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </xsl:element>
 =C2=A0 </xsl:template>

 =C2=A0 <xsl:template match=3D"*[@* and text()[normalize-space()]]">
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <xsl:element name=3D"{local-name()}" namesp=
ace=3D"{$namespace}">
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <xsl:apply-template=
s/>
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </xsl:element>
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <xsl:apply-templates select=3D"@*"/>
 =C2=A0 </xsl:template>

 =C2=A0 <xsl:template match=3D"@*[local-name() =3D $keepAttr]">
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <xsl:element name=3D"{local-name()}" namesp=
ace=3D"{$namespace}">
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <xsl:value-of select=3D"."/>
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </xsl:element>
 =C2=A0 </xsl:template>

</xsl:stylesheet>
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/3329386
or by email: [email protected]
--~--

--------------AA81F6D4BF21FA9DFD9753D6
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html>
  <head>
    <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF-8=
">
  </head>
  <body>
    <p><br>
    </p>
    <div class=3D"moz-cite-prefix">Am 22.05.2021 um 02:02 schrieb Sam
      Spade <a class=3D"moz-txt-link-abbreviated" href=3D"mailto:anonymousj=
[email protected]">[email protected]</a>:<br>
    </div>
    <blockquote type=3D"cite"
      cite=3D"mid:[email protected]">
      <meta http-equiv=3D"content-type" content=3D"text/html; charset=3DUTF=
-8">
      <div class=3D"ydpfce75138yahoo-style-wrap"
        style=3D"font-family:bookman old style, new york, times,
        serif;font-size:13px;">
        <div dir=3D"ltr" data-setdir=3D"false">
          <div>
            <p
              class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoListParagraph"
              style=3D"margin:0in 0in 0in
0.5in;line-height:normal;background-color:white;background-repeat:repeat;ba=
ckground-attachment:scroll;background-image:none;background-size:auto;"><fo=
nt
                size=3D"3" face=3D"Helvetica Neue, Helvetica, Arial,
                sans-serif"><span><span>2.<span
style=3D"font-style:normal;font-weight:normal;font-stretch:normal;font-size=
:7pt;line-height:normal;font-size-adjust:none;">=C2=A0=C2=A0=C2=A0=C2=A0
                    </span></span></span><span style=3D"color:black;">As I
                  point out in the post, </span></font></p>
            <font size=3D"3" face=3D"Helvetica Neue, Helvetica, Arial,
              sans-serif">
            </font>
            <p class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
              style=3D"margin:0in 0in 0in
0.25in;line-height:normal;background-color:white;background-repeat:repeat;b=
ackground-attachment:scroll;background-image:none;background-size:auto;"><f=
ont
                size=3D"3" face=3D"Helvetica Neue, Helvetica, Arial,
                sans-serif">=C2=A0</font></p>
            <p class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
              style=3D"margin:0in 0in 0in
0.25in;line-height:normal;background-color:white;background-repeat:repeat;b=
ackground-attachment:scroll;background-image:none;background-size:auto;"><s=
pan
                style=3D"color:black;"><a shape=3D"rect"
href=3D"https://stackoverflow.com/questions/67575484/what-attribute-node-ca=
nnot-follow-non-attribute-node-in-element-content-tells"
                  rel=3D"nofollow" target=3D"_blank" moz-do-not-send=3D"tru=
e">https://stackoverflow.com/questions/67575484/what-attribute-node-cannot-=
follow-non-attribute-node-in-element-content-tells</a></span></p>
            <p class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
              style=3D"margin:0in 0in 0in
0.25in;line-height:normal;background-color:white;background-repeat:repeat;b=
ackground-attachment:scroll;background-image:none;background-size:auto;">=
=C2=A0</p>
            <p class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
style=3D"margin:0in;line-height:normal;background-color:white;background-re=
peat:repeat;background-attachment:scroll;background-image:none;background-s=
ize:auto;"><font
                size=3D"3" face=3D"Helvetica Neue, Helvetica, Arial,
                sans-serif"><span style=3D"color:black;">it is not only
                  very difficult to search value if an
                  element (</span></font><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;currency&gt;</span>=
<span
                style=3D"font-size:12.0pt;font-family:Times New Roman,
                serif;color:#000096;">) </span><span
                style=3D"color:black;"><font
                  style=3D"background-color:inherit;" size=3D"3"
                  face=3D"Helvetica Neue, Helvetica, Arial, sans-serif">con=
tains
                  both element </font>(</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;id&gt;</span><span
                style=3D"font-size:12.0pt;font-family:Times New Roman,
                serif;color:#000096;">) </span><font size=3D"3"
                face=3D"Helvetica Neue, Helvetica, Arial, sans-serif"><span
                  style=3D"color:black;">and text value</span></font><span
                style=3D"font-size:12.0pt;font-family:Times New Roman,
                serif;color:#000096;">
                (USD) </span><font size=3D"3" face=3D"Helvetica Neue,
                Helvetica, Arial, sans-serif"><span style=3D"color:black;">=
but
                  also
                  returns false result.</span></font></p>
            <p class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
style=3D"margin:0in;line-height:normal;background-color:white;background-re=
peat:repeat;background-attachment:scroll;background-image:none;background-s=
ize:auto;">=C2=A0</p>
            <p class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
style=3D"margin:0in;line-height:normal;background-color:white;background-re=
peat:repeat;background-attachment:scroll;background-image:none;background-s=
ize:auto;"><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><span>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0
                </span></span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;amount&gt;</span><s=
pan
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><br
                  clear=3D"none">
                <span>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </span></span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;currency&gt;</span>=
<span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><br
                  clear=3D"none">
                <span>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </spa=
n></span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;id&gt;</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;">settlement=
Currency</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;/id&gt;</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;">USD</span>=
<span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;/currency&gt;</span=
><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><br
                  clear=3D"none">
                <span>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </span></span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;referenceAmount&gt;=
</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;">StandardIS=
DA</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;/referenceAmount&gt=
;</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><br
                  clear=3D"none">
                <span>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </span></span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;cashSettlement&gt;<=
/span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;">true</span=
><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;/cashSettlement&gt;=
</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><br
                  clear=3D"none">
                <span>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </span></span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;/amount&gt;</span><=
span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;background-color:white;background-repeat:repeat;background-attachment=
:scroll;background-image:none;background-size:auto;"></span></p>
            <p class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
style=3D"margin:0in;line-height:normal;background-color:white;background-re=
peat:repeat;background-attachment:scroll;background-image:none;background-s=
ize:auto;">=C2=A0</p>
            <p class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
style=3D"margin:0in;line-height:normal;background-color:white;background-re=
peat:repeat;background-attachment:scroll;background-image:none;background-s=
ize:auto;"><font
                size=3D"3" face=3D"Helvetica Neue, Helvetica, Arial,
                sans-serif"><span style=3D"color:black;">That </span><span
style=3D"font-size:12pt;color:black;background-color:white;background-repea=
t:repeat;background-attachment:scroll;background-image:none;background-size=
:auto;">USD</span><span
                  style=3D"font-size:12pt;color:black;"> </span><span
                  style=3D"color:black;">really is the value of</span></fon=
t><span
                style=3D"font-size:12.0pt;font-family:Times New Roman,
                serif;color:black;"> </span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;currency&gt;</span>=
<span
                style=3D"font-size:12.0pt;font-family:Times New Roman,
                serif;color:#000096;">.<font
                  style=3D"background-color:inherit;" size=3D"3"
                  face=3D"Helvetica Neue, Helvetica, Arial, sans-serif"> </=
font></span><font
                size=3D"3" face=3D"Helvetica Neue, Helvetica, Arial,
                sans-serif"><span style=3D"color:black;">In this case, it
                  is legitimate and
                  sensible to transform </span></font><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">id</span><span
                style=3D"color:black;"> <font
                  style=3D"background-color:inherit;" size=3D"3"
                  face=3D"Helvetica Neue, Helvetica, Arial, sans-serif">as
                  sibling element of its original
                  element</font> </span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;currency&gt;</span>=
<span
                style=3D"color:black;"> (<font
                  style=3D"background-color:inherit;" size=3D"3"
                  face=3D"Helvetica Neue, Helvetica, Arial, sans-serif">its
                  parent is still</font> </span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;amount&gt;</span><s=
pan
                style=3D"color:black;">) <font
                  style=3D"background-color:inherit;" size=3D"3"
                  face=3D"Helvetica Neue, Helvetica, Arial, sans-serif">to:=
</font></span></p>
            <p class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
style=3D"margin:0in;line-height:normal;background-color:white;background-re=
peat:repeat;background-attachment:scroll;background-image:none;background-s=
ize:auto;"><span
                style=3D"font-size:12.0pt;font-family:Times New Roman,
                serif;color:#000096;">=C2=A0</span></p>
            <p class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
style=3D"margin:0in;line-height:normal;background-color:white;background-re=
peat:repeat;background-attachment:scroll;background-image:none;background-s=
ize:auto;"><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;amount&gt;</span><s=
pan
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><br
                  clear=3D"none">
                <span>=C2=A0=C2=A0=C2=A0 </span></span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;currency&gt;</span>=
<span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;">USD</span>=
<span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;/currency&gt;</span=
><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><br
                  clear=3D"none">
                <span>=C2=A0=C2=A0=C2=A0 </span></span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;id&gt;</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;">settlement=
Currency</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;/id&gt;</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><br
                  clear=3D"none">
                <span>=C2=A0=C2=A0=C2=A0 </span></span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;referenceAmount&gt;=
</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;">StandardIS=
DA</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;/referenceAmount&gt=
;</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><br
                  clear=3D"none">
                <span>=C2=A0=C2=A0=C2=A0 </span></span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;cashSettlement&gt;<=
/span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;">true</span=
><span
                style=3D"font-size:12pt;font-family:Times New Roman,
                serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;/cashSettlement&gt;=
</span><span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;color:black;background-color:white;background-repeat:repeat;backgroun=
d-attachment:scroll;background-image:none;background-size:auto;"><br
                  clear=3D"none">
              </span><span style=3D"font-size:12pt;font-family:Times New
                Roman, serif;color:rgb(0, 0,
150);background-color:white;background-repeat:repeat;background-attachment:=
scroll;background-image:none;background-size:auto;">&lt;/amount&gt;</span><=
span
                style=3D"font-size:12pt;font-family:Times New Roman,
serif;background-color:white;background-repeat:repeat;background-attachment=
:scroll;background-image:none;background-size:auto;"></span></p>
            <div class=3D"ydp735fa017yiv9501170214ydpa3d97190MsoNormal"
style=3D"margin:0in;line-height:normal;background-color:white;background-re=
peat:repeat;background-attachment:scroll;background-image:none;background-s=
ize:auto;"><br
                clear=3D"none">
            </div>
            <font size=3D"3"><font face=3D"Helvetica Neue, Helvetica, Arial,
                sans-serif">The flattened XML is very searchable (an
                index on 'currency' is good enough) and can be
                transformed to JSON.</font></font></div>
          <div><br>
          </div>
        </div>
        <div><br>
        </div>
      </div>
      <div id=3D"ydpcf39a37fyahoo_quoted_1746359216"
        class=3D"ydpcf39a37fyahoo_quoted">
        <div style=3D"font-family:'Helvetica Neue', Helvetica, Arial,
          sans-serif;font-size:13px;color:#26282a;"><br clear=3D"none">
        </div>
      </div>
    </blockquote>
    <p><br>
    </p>
    <p>I am not sure an XSLT program can easily capture your rules but
      for the given sample, if you insert a check on elements whether
      they both have attributes and non-whitespace text content and in
      that case transform any attributes to sibling following the
      element, the result is as you wanted:</p>
    <p><br>
    </p>
    <p>&lt;xsl:stylesheet
      xmlns:xsl=3D<a class=3D"moz-txt-link-rfc2396E" href=3D"http://www.w3.=
org/1999/XSL/Transform">"http://www.w3.org/1999/XSL/Transform"</a><br>
      =C2=A0 version=3D"3.0"<br>
      =C2=A0 xmlns:xs=3D<a class=3D"moz-txt-link-rfc2396E" href=3D"http://w=
ww.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a><br>
      =C2=A0 exclude-result-prefixes=3D"#all"&gt;<br>
      =C2=A0 <br>
      =C2=A0 &lt;xsl:param name=3D"namespace"
      as=3D"xs:string"&gt;<a class=3D"moz-txt-link-freetext" href=3D"http:/=
/fc.fasset/product">http://fc.fasset/product</a>&lt;/xsl:param&gt;<br>
      <br>
      =C2=A0 &lt;xsl:param name=3D"root"
      as=3D"xs:string"&gt;requestProduct&lt;/xsl:param&gt;<br>
      =C2=A0 &lt;xsl:param name=3D"keepAttr" static=3D"yes" as=3D"xs:string=
*"
      select=3D"'href', 'id'"/&gt;<br>
      =C2=A0 <br>
      =C2=A0 &lt;xsl:strip-space elements=3D"*"/&gt;<br>
      =C2=A0 &lt;xsl:output indent=3D"yes"/&gt;<br>
      =C2=A0 <br>
      =C2=A0 &lt;xsl:template match=3D"/*"&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;xsl:element name=3D"{$root}" names=
pace=3D"{$namespace}"&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;xsl:apply-=
templates select=3D"@* , node()"/&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;/xsl:element&gt;<br>
      =C2=A0 &lt;/xsl:template&gt;<br>
      =C2=A0 <br>
      =C2=A0 &lt;xsl:template match=3D"*"&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;xsl:element name=3D"{local-name()}"
      namespace=3D"{$namespace}"&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;xsl:apply-=
templates select=3D"@* , node()"/&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;/xsl:element&gt;<br>
      =C2=A0 &lt;/xsl:template&gt;<br>
      =C2=A0 <br>
      =C2=A0 &lt;xsl:template match=3D"*[@* and text()[normalize-space()]]"=
&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;xsl:element name=3D"{local-name()}"
      namespace=3D"{$namespace}"&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;xsl:apply-=
templates/&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;/xsl:element&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;xsl:apply-templates select=3D"@*"/=
&gt;<br>
      =C2=A0 &lt;/xsl:template&gt;<br>
      =C2=A0 <br>
      =C2=A0 &lt;xsl:template match=3D"@*[local-name() =3D $keepAttr]"&gt;<=
br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;xsl:element name=3D"{local-name()}"
      namespace=3D"{$namespace}"&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;xsl:value-of select=3D=
"."/&gt;<br>
      =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &lt;/xsl:element&gt;<br>
      =C2=A0 &lt;/xsl:template&gt;<br>
      <br>
      &lt;/xsl:stylesheet&gt;</p>
    <p><br>
    </p>
  </body>
</html>
<div><!-- begin bl.html.trailer -->
<div style=3D"border-top:1px solid black; background-color: #dddddd;
color: #888888; font-size: smaller; padding: 5px; text-align: center;
font-family: arial,verdana,arial,sans-serif; margin-top:1em; clear:
both; margin: auto">
<a href=3D"http://www.mulberrytech.com/xsl/xsl-list">
XSL-List info and archive</a>
<div style=3D"text-align:center;">
<a style=3D"color: blue;"
  href=3D"http://lists.mulberrytech.com/unsub/xsl-list/3329386"
>EasyUnsubscribe</a>
(<a style=3D"color: blue;"
href=3D"mailto:[email protected]?subject=3Dremove"
>by email</a>)
</div>
</div>
<!-- end bl.html.trailer --></div>

--------------AA81F6D4BF21FA9DFD9753D6--