Derek Hart wrote:
I would want it this way:
<root>root
<child>child
<descendant>descendant</descendant>
</child>
</root>
Can you help with the code that could do this generically?
This stylesheet should do:
<?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" indent="yes"/>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{name()}"
namespace="{namespace-uri()}"><xsl:value-of
select="name()"/></xsl:attribute>
</xsl:template>
<xsl:template match="comment() | processing-instruction()">
<xsl:copy/>
</xsl:template>
<xsl:template match="text()">
<xsl:copy/>
</xsl:template>
<xsl:template match="*/node()[1][self::text() and
following-sibling::node()]">
<xsl:value-of select="concat(name(..), .)" />
</xsl:template>
<xsl:template match="*/node()[1][self::text() and
not(following-sibling::node())]">
<xsl:value-of select="name(..)"/>
</xsl:template>
</xsl:stylesheet>
VB.NET 1.x code to run the transformation with the above being
stylesheet.xsl, file.xml being the input file name and result.xml being
the output file name is e.g.
Dim XsltProcessor As New XslTransform
XsltProcessor.Load("stylesheet.xsl")
XsltProcessor.Transform(_
New XPathDocument("file.xml", XmlSpace.Preserve),_
"result.xml",_
Nothing)
With VB.NET 2.0 you could do e.g.
Dim XsltProcessor As New XslCompiledTransform()
XsltProcessor.Load("stylesheet.xsl")
XsltProcessor.Transform("file.xml", "result.xml")
Does that help?
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/