[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Transform selected attribute to element when eleme

Subject: Re: 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 21:28:02 -0000
Re:  Transform selected attribute to element when eleme
p b$o8





Excellent Collaboration!!!B 




    On Saturday, May 22, 2021, 12:03:32 p.m. MST, Martin Honnen
martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

 On 22.05.2021 20:51, Sam Spade anonymousjuly1@xxxxxxxx wrote:
> As you can see,B  the unwanted attribute *currencyScheme* still persists.
> 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="http://www.w3.org/1999/XSL/Transform"
B  version="3.0"
B  xmlns:xs="http://www.w3.org/2001/XMLSchema"
B  exclude-result-prefixes="#all">

B  <xsl:param name="namespace"
as="xs:string">http://fc.fasset/product</xsl:param>

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

B  <xsl:strip-space elements="*"/>
B  <xsl:output indent="yes"/>

B  <xsl:template match="/*">
B  B  B  <xsl:element name="{$root}" namespace="{$namespace}">
B  B  B  B  B  <xsl:apply-templates select="@*[local-name() = $keepAttr],
node()"/>
B  B  B  </xsl:element>
B  </xsl:template>

B  <xsl:template match="*">
B  B  B  <xsl:element name="{local-name()}" namespace="{$namespace}">
B  B  B  B  B  <xsl:apply-templates select="@*[local-name() = $keepAttr],
node()"/>
B  B  B  </xsl:element>
B  </xsl:template>

B  <xsl:template match="*[@* and text()[normalize-space()]]">
B  B  B  <xsl:element name="{local-name()}" namespace="{$namespace}">
B  B  B  B  B  <xsl:apply-templates/>
B  B  B  </xsl:element>
B  B  B  <xsl:apply-templates select="@*[local-name() = $keepAttr]"/>
B  </xsl:template>

B  <xsl:template match="@*">
B  B  B  <xsl:element name="{local-name()}" namespace="{$namespace}">
B  B  B  B  <xsl:value-of select="."/>
B  B  B  </xsl:element>
B  </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="@*[not(local-name() = $keepAttr)]"/>`.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.