Re: generalized template to transform elements to attributes

Subject: Re: generalized template to transform elements to attributes
From: Honglin Su <hosu@xxxxxxxxxxx>
Date: Tue, 03 Aug 1999 16:50:36 -0400
Can you tell me which XSLT processor you are using? I use LotusXSL, it seems
to have  some pattern warning on attribute name.

Thank you!

Honglin

David Carlisle wrote:

> <xsl:stylesheet
>   xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";
>   default-space="strip"
>   indent-result="yes">
>
> <xsl:template match="*">
> <xsl:copy>
> <xsl:for-each select="@*|*[not(* or @*)]">
> <xsl:attribute name="{name(.)}"><xsl:value-of select="."/>
> </xsl:attribute>
> </xsl:for-each>
> <xsl:apply-templates select="*[* or @*]|text()"/>
> </xsl:copy>
> </xsl:template>
>
> </xsl:stylesheet>
>
> appears to convert
>
> <atom  phase="gas">
>    <name>Hydrogen</name>
>    <symbol>H</symbol>
>    <boiling_point units="Kelvin">20.28</boiling_point>
> </atom>
>
> into
>
> <atom phase="gas" name="Hydrogen" symbol="H">
> <boiling_point units="Kelvin">20.28</boiling_point>
> </atom>
>
> The first select picks up attributes and elements that don't have
> element children or attributes, and makes attributes of them.
> The second select picks up elements with element children or attributes,
> and text nodes.
>
> as written, comments, pis etc get thrown away, but could be added to the
> second select.
>
> David
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread