Subject: Re: [xsl] Transform selected attribute to element when element already has a value | XSLT 2.0 From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 22 May 2021 19:03:31 -0000 |
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?
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="#all">
<xsl:param name="namespace" as="xs:string">http://fc.fasset/product</xsl:param>
<xsl:param name="root" as="xs:string">requestProduct</xsl:param> <xsl:param name="keepAttr" static="yes" as="xs:string*" select="'href', 'id'"/>
<xsl:strip-space elements="*"/> <xsl:output indent="yes"/>
<xsl:template match="/*"> <xsl:element name="{$root}" namespace="{$namespace}"> <xsl:apply-templates select="@*[local-name() = $keepAttr], node()"/> </xsl:element> </xsl:template>
<xsl:template match="*"> <xsl:element name="{local-name()}" namespace="{$namespace}"> <xsl:apply-templates select="@*[local-name() = $keepAttr], node()"/> </xsl:element> </xsl:template>
<xsl:template match="*[@* and text()[normalize-space()]]"> <xsl:element name="{local-name()}" namespace="{$namespace}"> <xsl:apply-templates/> </xsl:element> <xsl:apply-templates select="@*[local-name() = $keepAttr]"/> </xsl:template>
<xsl:template match="@*"> <xsl:element name="{local-name()}" namespace="{$namespace}"> <xsl:value-of select="."/> </xsl:element> </xsl:template>
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, Sam Spade anonymousj | Thread | Re: [xsl] Transform selected attrib, Sam Spade anonymousj |
Re: [xsl] Transform selected attrib, Sam Spade anonymousj | Date | Re: [xsl] Transform selected attrib, Sam Spade anonymousj |
Month |