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

Re: Got some cool XSLT code that assembles parts toget

Subject: Re: Got some cool XSLT code that assembles parts together to create larger parts?
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 19 Mar 2012 20:40:05 +0000
Re:  Got some cool XSLT code that assembles parts toget
Following relational tradition, it's perhaps more usual to model a hierarchy the other way around, with the child pointing to the parent rather than the parent to the children; but either way works perfectly well (and doing it this way makes it easier to maintain the order of children within their parent).

In general terms the solution is to use the usual xsl:apply-templates recursive descent model, but using the logical hierarchy rather than the XML parent-child relationship. So write a function getChildren() and then use apply-templates select="getChildren(.)". In this particular case I'm not quite sure what you do if a parent has more than one child, but the getChildren function might be simply a call on id(@idref).

Michael Kay
Saxonica

On 19/03/2012 19:58, Costello, Roger L. wrote:
Hi Folks,

I need code that assembles parts together to create larger parts.

For example, consider this XML document:
------------------------------------------------------
<Document>
     <head id="head" idref="body" />

<body id="body" idref="leg" />

<leg id="leg" idref="toes" />

<toes id="toes" />

</Document>
------------------------------------------------------
It contains a lot of parts - head, body, leg, toes.

Each part references another part (except toes doesn't reference another part).

If a part references another part, I would like to inline the referenced part, and then recurses on the referenced part.

After assembly the document should be this:
------------------------------------------------------
<Document>
     <head id="head">
         <body id="body">
             <leg id="leg">
                 <toes id="toes" />
             </leg>
         </body>
     </head>

     <body id="body">
         <leg id="leg">
             <toes id="toes" />
         </leg>
     </body>

     <leg id="leg">
         <toes id="toes" />
     </leg>

     <toes id="toes" />
</Document>
------------------------------------------------------

I wonder if this particular example is a special case of a general case of assembling parts together to create larger parts?

In any event, do you have some cool code that does the job?

Note that it's possible for a part A to reference a part B which references part A (i.e., circular reference). So the code must avoid going into an infinite loop.

/Roger

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.