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

RE: merge tree structure with no redundancy

Subject: RE: merge tree structure with no redundancy
From: "McNally, David" <David.McNally@xxxxxxxxxx>
Date: Fri, 2 Aug 2002 14:20:52 -0400
merge tree
BTW, I typed the wrong copy of subscriber.xml.  It should be (note the
corrected id element):

<?xml version="1.0" encoding="ISO-8859-1"?>
<a>
  <subscribers>
    <subscriber>
      <id id="1"/>
      <path>
        <node type="T1" name="N1">
          <node type="T2" name="N2">
            <node type="T3" name="N3"/>
          </node>
        </node>
      </path>
    </subscriber>
    <subscriber>
      <id id="2"/>
      <path>
        <node type="T1" name="N1">
          <node type="T2" name="N2">
            <node type="T3" name="N4"/>
          </node>
        </node>
      </path>
    </subscriber>
  </subscribers>
</a>

David.

> -----Original Message-----
> From: McNally, David 
> Sent: Friday, August 02, 2002 1:11 PM
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Subject: RE:  merge tree structure with no redundancy
> 
> 
> When in doubt, reach for keys and the Meunchian technique, both well
> described in the faq.
> 
> Basically you need two keys - "me" which is used to figure 
> out whether each
> node is the first, in document order, with a particular @type 
> and @name
> pair.  The second, "parent", is used to process all the nodes who are
> children of a particular @type and @name pair, regardless of 
> where they are
> in the file.  So basically the node template decides if the 
> node is the
> first with its type/name - if it isn't it does nothing.  If it is, it
> outputs the element and attributes, and then applies 
> templates to all nodes
> that are "children" of that node, based on the "parent" key.
> 
> I think this works properly, but handle with care...
> 
> <?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:key name="parent" match="node"
> use="concat(parent::node/@type,'::',parent::node/@name)"/>
> <xsl:key name="me" match="node" use="concat(@type,'::',@name)"/>
> 
> <xsl:template match="a">
> <a>
> 	<xsl:apply-templates select="subscribers/subscriber/path/node"/>
> </a>
> </xsl:template>
> 
> <xsl:template match="node">
> 	<xsl:variable name="mykey" select="concat(@type,'::',@name)"/>
> 	<xsl:choose>
> 		<xsl:when test="generate-id(.) =
> generate-id(key('me',$mykey)[1])">
> 			<xsl:element name="{name()}">
> 				<xsl:copy-of select="@*"/>
> 				<xsl:if test="not(node)">
> 					<xsl:attribute name="id">
> 						<xsl:value-of
> select="ancestor::subscriber/id/@id"/>
> 					</xsl:attribute>
> 				</xsl:if>
> 				<xsl:apply-templates
> select="key('parent',concat(@type,'::',@name))"/>
> 			</xsl:element>
> 		</xsl:when>
> 	</xsl:choose>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
[snip]


---------------------------------------

The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission.  If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited.  If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments.  Thank you.

Every effort is made to keep our network free from viruses.  You should, however, review this e-mail message, as well as any attachment thereto, for viruses.  We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.


 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.