[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Hierarchy to Flat Structure

Subject: Re: Hierarchy to Flat Structure
From: Geert Bormans <geert@xxxxxxxxxxxxxxxxxxx>
Date: Sun, 17 Mar 2013 10:59:36 +0100
Re:  Hierarchy to Flat Structure
Hi Rick,

If you add a template for your root

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

you could simply do this

   <xsl:template match="*">
        <xsl:copy-of select="." />
    </xsl:template>

for covering all the sibling notes

I have two observations however.

- it is worth looking into so called "sibling recursion" for doing such a task in XSLT1.
I will post an example in a minute


- it is worth considering XSLT2 for this task. Let me know if that is a viable path.
It has grouping functionality built in for a task like this


Cheers

Geert




At 02:57 17/03/2013, you wrote:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes" />

    <xsl:template match="Cases/Cases">
    <Cases>
        <xsl:apply-templates select="Category" />
    </Cases>
    </xsl:template>

    <xsl:template match="Category">
        <Case>
            <Category><xsl:value-of select="." /></Category>
            <xsl:apply-templates
                select="following-sibling::CaseTitle
                [generate-id(preceding-sibling::Category[1])
                = generate-id(current())]" />
            <xsl:apply-templates
                select="following-sibling::Institution
                [generate-id(preceding-sibling::Category[1])
                = generate-id(current())]" />
        </Case>
    </xsl:template>

    <xsl:template match="CaseTitle">
        <xsl:copy-of select="." />
    </xsl:template>

    <xsl:template match="Institution">
        <xsl:copy-of select="." />
    </xsl:template>

</xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.