|
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 21:28:02 -0000 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Transform selected attrib, Martin Honnen martin | Thread | [xsl] How to fuzz the last four dig, Roger L Costello cos |
| Re: [xsl] Transform selected attrib, Martin Honnen martin | Date | [xsl] [ANN] Balisage Late-breaking , B Tommie Usdin btusd |
| Month |