Re: [xsl] Réf. : RE : [xsl] XML tags to XML attributes with XSL

Subject: Re: [xsl] Réf. : RE : [xsl] XML tags to XML attributes with XSL
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 22 Oct 2003 11:14:51 -0400

Jarno suggested using xsl:copy-of, and you reported it placed the value of your attribute into element content.

Are you sure you said copy-of, not value-of? xsl:value-of would give the result you reported, but xsl:copy-of would (as Jarno said) copy the attribute as an attribute (not place its value into the content).

At 04:50 AM 10/22/2003, you wrote:

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

and it seems to work now.

This works because you are selecting attributes (select="@*") and also matching them with the same template, which copies them.

The line <xsl:apply-templates select="Attributes"/> is, however, spurious. It's not doing anything at all, since you don't have any child elements named "Attributes" -- and if you did, it would break your stylesheet and your actual attributes would fail to be copied, since they are being copied by the next instruction <xsl:apply-templates select="* | @* | text()"/>, and you can't add attributes to an element node after other things have been placed in its content (as would presumably happen if you had element children named "Attributes").

So you probably want to delete that line (try it; it will still work) ... and maybe go back to Jarno's idea as it's a bit tighter (albeit a little less adaptable).


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

XSL-List info and archive:

Current Thread