xsl-list
[Top] [All Lists]

Re: Newby Question reformatting xml

2003-02-17 07:12:32
Michael A. Thompson wrote:

My XSL file:

<?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="AAA">
        <xsl:element name="AAA">
            <xsl:apply-templates select="DDD" />
        </xsl:element>
    </xsl:template>
<xsl:template match="DDD">
        <xsl:element name="DDD">
            <xsl:apply-templates select="BBB"></xsl:apply-templates>
        </xsl:element>
</xsl:template> <xsl:template match="BBB">
        <xsl:element name="BBB">
            <xsl:attribute name="num">
                <xsl:value-of select="//DDD/@id"></xsl:value-of>
            </xsl:attribute>
            <xsl:value-of select="."></xsl:value-of>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Try simple one:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <xsl:template match="AAA">
        <AAA>
            <xsl:apply-templates select="DDD"/>
        </AAA>
    </xsl:template>
    <xsl:template match="DDD">
        <DDD>
            <xsl:apply-templates select="BBB"/>
        </DDD>
    </xsl:template>
    <xsl:template match="BBB">
        <BBB num="{ancestor::DDD[1]/@id}">
            <xsl:value-of select="."/>
        </BBB>
    </xsl:template>
</xsl:stylesheet>

--
Oleg Tkachenko
Multiconn Technologies, Israel


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



<Prev in Thread] Current Thread [Next in Thread>