[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Rebuild an element without copying defaulted attributes?


Subject: Re: [xsl] Rebuild an element without copying defaulted attributes?
From: "Abel Braaksma (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 12 Aug 2014 17:04:03 -0000

> My problem is the unchanged.
>
>
> <xsl:template match="*">
> <xsl:element name="{name(.)}">
> <xsl:for-each select="@*">
>     <xsl:attribute name="{name(current())}" ><xsl:value-of
> select="."/></xsl:attribute> </xsl:for-each> <xsl:apply-templates/>
> </xsl:element> </xsl:template>

If you want to differentiate between an explicitly defaulted attribute in your
input (<pre xml:space="preserve" />) and an implicitly defaulted attribute
(<pre />) you are out of luck with standard XSLT. But if it works for you if
you just make all attributes of xml:space implicitly defaulted, you can do the
following:

<xsl:template match="node() |@*">
    <xsl:copy>
        <xsl:apply-templates select="node() | @*" />
    </xsl:copy>
</xsl:template>

<xsl:template match="@xml:space[. = 'preserve']" />

Now the output will not contain any xml:space="preserve", which, if it is part
of your DTD, has the same semantic meaning as copying the implicit default
attributes which you did in your example code.

This is also a bit of a more convenient way to write the matching template you
wrote, as the xsl:copy will automatically copy the context node, which you
were doing manually (but: you were not processing the children, so my code and
your code is not exactly the same).

Cheers,

Abel Braaksma
Exselt streaming XSLT 3.0 processor
http://exselt.net


Current Thread
Keywords