xslt apply-templates in second level

Posted by m00sila on Stack Overflow See other posts from Stack Overflow or by m00sila
Published on 2010-06-14T14:59:24Z Indexed on 2010/06/14 15:02 UTC
Read the original article Hit count: 326

Filed under:
|

I cannot wrap <panel> tags to second level individual items as shown in Expected result bellow. But with the xslt i have written, all 1.x get into single node. Please help me.

Source xml

<root>
    <step id="1">
        <content>
            <text>
                1.0 Sample first level step text
            </text>
        </content>
        <content/>
        <step>
            <content>
                <text>
                    1.1 Sample second level step text
                </text>
            </content>
        </step>
        <step>
            <content>
                <text>
                    1.2 Sample second level step text
                </text>
            </content>
        </step>
        <step>
            <content>
                <text>
                    1.3 Sample second level step text
                </text>
            </content>
        </step>
    </step>
</root>

Expected output

<panel>
    <panel>
        1.0 Sample first level step text
    </panel>
    <panel>
        1.1 Sample second level step text
    </panel>
    <panel>
        1.2 Sample second level step text
    </panel>
    <panel>
        1.3 Sample second level step text
    </panel>
</panel>

My XSLT

<xsl:template match="/">
    <panel>
        <xsl:apply-templates/>
    </panel>
</xsl:template>

<xsl:template match="root/step" >
    <panel>
        <panel>
            <xsl:apply-templates select ="content/text/node()"></xsl:apply-templates>
        </panel>
        <panel>
            <xsl:apply-templates select ="step/content/text/node()"></xsl:apply-templates>
        </panel>
    </panel>
</xsl:template>

© Stack Overflow or respective owner

Related posts about xslt

Related posts about xsl