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

"Sam Spade [email protected]" <[email protected]> Sat, 22 May 2021 21:28:09 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
------=_Part_692451_927411222.1621718672255
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

=20
=F0=9F=8E=86 =E2=9D=A4=EF=B8=8F





Excellent Collaboration!!!=C2=A0=20




    On Saturday, May 22, 2021, 12:03:32 p.m. MST, Martin Honnen martin.honn=
[email protected] <[email protected]> wrote:=20=20
=20
 On 22.05.2021 20:51, Sam Spade [email protected] wrote:
> As you can see,=C2=A0 the unwanted attribute *currencyScheme* still persi=
sts.
> Is there a way to remove the attribute which is not in the $keepAttr list?

Perhaps in this case it is better to filter when applying templates:

<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 <xsl:element name=3D"{$root}" namespace=3D"{$namespace=
}">
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <xsl:apply-templates select=3D"@*[local-=
name() =3D $keepAttr],
node()"/>
=C2=A0 =C2=A0 =C2=A0 </xsl:element>
=C2=A0 </xsl:template>

=C2=A0 <xsl:template match=3D"*">
=C2=A0 =C2=A0 =C2=A0 <xsl:element name=3D"{local-name()}" namespace=3D"{$na=
mespace}">
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <xsl:apply-templates select=3D"@*[local-=
name() =3D $keepAttr],
node()"/>
=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 <xsl:element name=3D"{local-name()}" namespace=3D"{$na=
mespace}">
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <xsl:apply-templates/>
=C2=A0 =C2=A0 =C2=A0 </xsl:element>
=C2=A0 =C2=A0 =C2=A0 <xsl:apply-templates select=3D"@*[local-name() =3D $ke=
epAttr]"/>
=C2=A0 </xsl:template>

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

</xsl:stylesheet>


As the built-in templates copy attribute values through I think you
would otherwise need to prevent that with `<xsl:template
match=3D"@*[not(local-name() =3D $keepAttr)]"/>`.


=20=20
--~----------------------------------------------------------------
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]
--~--

------=_Part_692451_927411222.1621718672255
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div class=3D"ydp4a1f0799yahoo-style-wrap" style=
=3D"font-family:bookman old style, new york, times, serif;font-size:13px;" =
dir=3D"ltr" data-setdir=3D"false"><div></div>
        <div dir=3D"ltr" data-setdir=3D"false"><div dir=3D"ltr" data-setdir=
=3D"false"><div><span></span><div><font size=3D"7"><span><p class=3D"ydpae7=
6dd77MsoNormal" dir=3D"ltr" data-setdir=3D"false"><b><span style=3D"backgro=
und-color: rgb(255, 255, 255);"><span style=3D"text-transform:uppercase"><s=
pan>=F0=9F=8E=86 </span><span>=E2=9D=A4=EF=B8=8F</span></span></span></b></=
p></span></font></div><span></span><div><span><p class=3D"ydpae76dd77MsoNor=
mal" dir=3D"ltr" data-setdir=3D"false"><b><span style=3D"background-color: =
rgb(255, 255, 255);"><font style=3D"background-color: inherit;" size=3D"5">=
<i><span style=3D"text-transform:uppercase"></span></i></font></span></b></=
p></span></div><span><p class=3D"ydp3429755bMsoNormal"><span></span></p><p =
class=3D"ydpae76dd77MsoNormal" dir=3D"ltr" data-setdir=3D"false"><b><span s=
tyle=3D"background-color: rgb(255, 255, 255);"><font style=3D"background-co=
lor: inherit;" size=3D"5"><i><span style=3D"text-transform:uppercase">Excel=
lent Collaboration!!!&nbsp; <br></span></i></font></span></b></p></span><p>=
</p></div></div><span></span></div><div><span>

</span></div><div><br></div>
=20=20=20=20=20=20=20=20
        </div><div id=3D"ydp50db8485yahoo_quoted_2272755672" class=3D"ydp50=
db8485yahoo_quoted">
            <div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
                <div>
                    On Saturday, May 22, 2021, 12:03:32 p.m. MST, Martin Ho=
nnen [email protected] &lt;[email protected]&gt; w=
rote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div dir=3D"ltr">On 22.05.2021 20:51, Sam Spade <a sha=
pe=3D"rect" href=3D"mailto:[email protected]" rel=3D"nofollow" target=
=3D"_blank">[email protected]</a> wrote:<br clear=3D"none">&gt; As yo=
u can see,&nbsp; the unwanted attribute *currencyScheme* still persists.<br=
 clear=3D"none">&gt; Is there a way to remove the attribute which is not in=
 the $keepAttr list?<br clear=3D"none"><br clear=3D"none">Perhaps in this c=
ase it is better to filter when applying templates:<br clear=3D"none"><br c=
lear=3D"none">&lt;xsl:stylesheet xmlns:xsl=3D"<a shape=3D"rect" href=3D"htt=
p://www.w3.org/1999/XSL/Transform" rel=3D"nofollow" target=3D"_blank">http:=
//www.w3.org/1999/XSL/Transform</a>"<br clear=3D"none">&nbsp;  version=3D"3=
.0"<br clear=3D"none">&nbsp;  xmlns:xs=3D"<a shape=3D"rect" href=3D"http://=
www.w3.org/2001/XMLSchema" rel=3D"nofollow" target=3D"_blank">http://www.w3=
.org/2001/XMLSchema</a>"<br clear=3D"none">&nbsp;  exclude-result-prefixes=
=3D"#all"&gt;<br clear=3D"none"><br clear=3D"none">&nbsp;  &lt;xsl:param na=
me=3D"namespace"<br clear=3D"none">as=3D"xs:string"&gt;<a shape=3D"rect" hr=
ef=3D"http://fc.fasset/product" rel=3D"nofollow" target=3D"_blank">http://f=
c.fasset/product</a>&lt;/xsl:param&gt;<br clear=3D"none"><br clear=3D"none"=
>&nbsp;  &lt;xsl:param name=3D"root" as=3D"xs:string"&gt;requestProduct&lt;=
/xsl:param&gt;<br clear=3D"none">&nbsp;  &lt;xsl:param name=3D"keepAttr" st=
atic=3D"yes" as=3D"xs:string*"<br clear=3D"none">select=3D"'href', 'id'"/&g=
t;<br clear=3D"none"><br clear=3D"none">&nbsp;  &lt;xsl:strip-space element=
s=3D"*"/&gt;<br clear=3D"none">&nbsp;  &lt;xsl:output indent=3D"yes"/&gt;<b=
r clear=3D"none"><br clear=3D"none">&nbsp;  &lt;xsl:template match=3D"/*"&g=
t;<br clear=3D"none">&nbsp; &nbsp; &nbsp;  &lt;xsl:element name=3D"{$root}"=
 namespace=3D"{$namespace}"&gt;<br clear=3D"none">&nbsp; &nbsp; &nbsp; &nbs=
p; &nbsp;  &lt;xsl:apply-templates select=3D"@*[local-name() =3D $keepAttr]=
,<br clear=3D"none">node()"/&gt;<br clear=3D"none">&nbsp; &nbsp; &nbsp;  &l=
t;/xsl:element&gt;<br clear=3D"none">&nbsp;  &lt;/xsl:template&gt;<br clear=
=3D"none"><br clear=3D"none">&nbsp;  &lt;xsl:template match=3D"*"&gt;<br cl=
ear=3D"none">&nbsp; &nbsp; &nbsp;  &lt;xsl:element name=3D"{local-name()}" =
namespace=3D"{$namespace}"&gt;<br clear=3D"none">&nbsp; &nbsp; &nbsp; &nbsp=
; &nbsp;  &lt;xsl:apply-templates select=3D"@*[local-name() =3D $keepAttr],=
<br clear=3D"none">node()"/&gt;<br clear=3D"none">&nbsp; &nbsp; &nbsp;  &lt=
;/xsl:element&gt;<br clear=3D"none">&nbsp;  &lt;/xsl:template&gt;<br clear=
=3D"none"><br clear=3D"none">&nbsp;  &lt;xsl:template match=3D"*[@* and tex=
t()[normalize-space()]]"&gt;<br clear=3D"none">&nbsp; &nbsp; &nbsp;  &lt;xs=
l:element name=3D"{local-name()}" namespace=3D"{$namespace}"&gt;<br clear=
=3D"none">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &lt;xsl:apply-templates/&gt;<=
br clear=3D"none">&nbsp; &nbsp; &nbsp;  &lt;/xsl:element&gt;<br clear=3D"no=
ne">&nbsp; &nbsp; &nbsp;  &lt;xsl:apply-templates select=3D"@*[local-name()=
 =3D $keepAttr]"/&gt;<br clear=3D"none">&nbsp;  &lt;/xsl:template&gt;<br cl=
ear=3D"none"><br clear=3D"none">&nbsp;  &lt;xsl:template match=3D"@*"&gt;<b=
r clear=3D"none">&nbsp; &nbsp; &nbsp;  &lt;xsl:element name=3D"{local-name(=
)}" namespace=3D"{$namespace}"&gt;<br clear=3D"none">&nbsp; &nbsp; &nbsp; &=
nbsp;  &lt;xsl:value-of select=3D"."/&gt;<br clear=3D"none">&nbsp; &nbsp; &=
nbsp;  &lt;/xsl:element&gt;<br clear=3D"none">&nbsp;  &lt;/xsl:template&gt;=
<br clear=3D"none"><br clear=3D"none">&lt;/xsl:stylesheet&gt;<br clear=3D"n=
one"><br clear=3D"none"><br clear=3D"none">As the built-in templates copy a=
ttribute values through I think you<br clear=3D"none">would otherwise need =
to prevent that with `&lt;xsl:template<br clear=3D"none">match=3D"@*[not(lo=
cal-name() =3D $keepAttr)]"/&gt;`.<br clear=3D"none"><br clear=3D"none"><br=
 clear=3D"none"></div></div></div>
            </div>
        </div></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>

------=_Part_692451_927411222.1621718672255--