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

Re: Rebuild an element without copying defaulted attr

Subject: Re: 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
Re:  Rebuild an element without copying defaulted  attr
> 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

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.