Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - xslt >Thread Next - Re: xslt Re: xsltTo: NULL Date: 4/7/2005 1:34:00 PM
debugger wrote:
> I have an xml source of the following type:
> <tag attrib="val1">
> <tag2 attribute="something" />
> </tag>
> <tag attrib="val2">
> <tag2 />
> </tag>
> <tag attrib="val3">
> <tag2 attribute="zzz" />
> </tag>
> <tag1 attrib="val4">
> <tag2 attribute="abc" />
> </tag>
That is not well-formed, but assuming you have the well-formed source
document
<?xml version="1.0" encoding="UTF-8"?>
<root>
<tag attrib="val1">
<tag2 attribute="something" />
</tag>
<tag attrib="val2">
<tag2 />
</tag>
<tag attrib="val3">
<tag2 attribute="zzz" />
</tag>
<tag1 attrib="val4">
<tag2 attribute="abc" />
</tag1>
</root>
> I want to use xsl transform of this xml source into:
>
> <val1>something</val1>
> <val2></val2>
> <val3>zzz</val3>
> <val4>abc</val4>
then you get your result (plus a root element) with
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="tag | tag1">
<xsl:element name="{@attrib}"><xsl:value-of select="tag2/@attribute"
/></xsl:element>
</xsl:template>
<xsl:template match="root">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates select="*" />
</xsl:copy>
</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 | |||
|
