Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Transform fields to node attributes? [Thread Next] Re: Transform fields to node attributes?To: NULL Date: 1/3/2009 8:42:00 AM Can be a little bit simpler, just override the identity rule like this:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Event/*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Cheers,
Dimitre Novatchev
"Martin Honnen" <mahotrash@y...> wrote in message
news:OeRfUWabJHA.1328@T......
> Savvoulidis Iordanis wrote:
>> How do I transform the following XML :
>> <Event code="100 ">
>> <Status>FINAL</Status>
>> <League>AGK</League>
>> <Date>10/11/2008</Date>
>> <Time>21:45</Time>
>> </Event>
>>
>> to the one below:
>>
>> <Event code="100 " Status="FINAL" League="AGK" Date="10/11/2008"
>> Time="21:45" />
>
> Here is a stylesheet:
>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
> <xsl:template match="Event">
> <xsl:copy>
> <xsl:apply-templates select="@* | *[not(*)]"/>
> </xsl:copy>
> </xsl:template>
>
> <xsl:template match="@*">
> <xsl:copy/>
> </xsl:template>
>
> <xsl:template match="Event/*[not(*)]">
> <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
> <xsl:value-of select="."/>
> </xsl:attribute>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
