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

Re: Ordering of Blocks based on Input/Output

Subject: Re: Ordering of Blocks based on Input/Output
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Tue, 08 May 2001 19:45:56 +0100
norton b2
Dan Diebolt wrote:
> 
> Starting from B1, there are only two ways to order the
> blocks so that each Block's inputs are provided by a
> proceeding Block's output:
> 
> B1 , B2 , B3 , B4 , B5
> B1 , B3 , B2 , B4 , B5
> 
> My problem is to produce *one* such feasible ordering of
> the blocks. 

The attached seems fairly efficient.

Hope this helps - a fun challenge at the end of the day!

Francis.

C:\xml>type t.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:template match="/">
    <order>
      <!-- call the order function with the parameters -->
      <xsl:call-template name="order">
        <xsl:with-param name="done" select="/.."/>
        <xsl:with-param name="todo" select="/root/system/block/name"/>
      </xsl:call-template>
    </order>
  </xsl:template>
  <!-- recurse through this printing out one block at a time -->
  <xsl:template name="order">
    <xsl:param name="done"/>
    <xsl:param name="todo"/>
    <!-- always need a terminate condition in recursive functions -->
    <xsl:if test="count($todo) > 0">
      <!-- links into todo -->
      <xsl:variable name="into"
select="/root/system/connect[input/@block = $todo]"/>
      <!-- find first block $todo that has no inputs from any (other)
block in $todo -->
      <xsl:variable name="next" select="$todo[. !=
$into/output/@block][1]"/>
      <!-- now copy it out -->
      <xsl:copy-of select="$next"/>
      <!-- now recurse with $next transferred from $todo to $done -->
      <xsl:call-template name="order">
        <xsl:with-param name="done" select="$done | $next"/>
        <xsl:with-param name="todo" select="$todo[generate-id(.) !=
generate-id($next)]"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

C:\xml>saxon t.xml t.xslt
<?xml version="1.0" encoding="UTF-8"?>
<order>
   <name>B1</name>
   <name>B2</name>
   <name>B3</name>
   <name>B4</name>
   <name>B5</name>
</order>
C:\xml>

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


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.