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

Re: New user issue: use of Muenchian method

Subject: Re: New user issue: use of Muenchian method
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 21 Sep 2007 11:10:19 -0400
Re:  New user issue:  use of Muenchian method
At 2007-09-21 09:05 -0500, Dunk, Michael (Mike) wrote:
Enhancing that xsl to include additional data about subject-areas, I am
looking to produce some xml in the following format.

<subject-areas>
  <subject-area name="System - Team Structure">
                        <included-table name="team"/>
                        <included-table name="team_level"/
  </subject-area>
</subject-areas>

I am close to output the above xml apart from the included-table name
attribute value.

The source xml that describes subject-areas has included-tables (aka
Referenced_Entities) which are listed by giving only their entity
reference. For my output xml I need to be look up the entity references
in another data structure <Entity> in the source xml. An example of the
source xml is shown below:

<Subject_Areas_and_Enities>

<Subject_Area id="{661CB799-677D-4359-A128-46DC5078D9D5}+00000000"
name="System - Team Structure">
  <Subject_AreaProps>
    <Name>System - Team Structure</Name>
    <Referenced_Entities_Array>
      <Referenced_Entities
index="0">{5D393595-7786-46CF-9C35-E68DBD5FC979}+00000000
      </Referenced_Entities>
      <Referenced_Entities
index="1">{30882953-C9DF-4911-829E-C1FC00BD8DF8}+00000000</Referenced_En
tities>
      </Referenced_Entities_Array>

<Entity id="{5D393595-7786-46CF-9C35-E68DBD5FC979}+00000000"
name="Team">
  <EntityProps>
    <Definition>
      A Team is a group of workers in an organization.
    </Definition>
   <EnityProps>
</Entity>
</Subject_Areas_and_Enities>

The latest xsl I have developed to solve this issue is as follows:

<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://www.ca.com/erwin/data">
<xsl:output method="xml" indent="yes"/>

<xsl:key name="entity-id" match="Entity_Groups/Entity" use="@id"/>

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

Here you are pushing the document element (which you don't describe) and then the built-in template rules will merrily process all of your tree structure.


</xsl:template>

<xsl:template match="Subject_Area_Groups">

You are only catching one element here ... any ancestors or siblings of this element will pass their descendants through the built-in template rules, resulting in the text nodes of those descendants appearing in your output.


  <Subject_Areas>
    <xsl:apply-templates select="Subject_Area"/>
  </Subject_Areas>
</xsl:template>

<xsl:template match="Subject_Area">
 <Subject_Area>
  <xsl:value-of select="@name"/>
  <xsl:apply-templates
select="Subject_AreaProps/Referenced_Entities_Array/Referenced_Entities"
/>
 </Subject_Area>
</xsl:template>

<xsl:template
match="Subject_AreaProps/Referenced_Entities_Array/Referenced_Entities">
 <included-table>
  <xsl:value-of select="text()"/>

You probably don't want "text()" here ... I suspect you want "." ... only very rarely do I ever need text() because a given element may have multiple text node children separated by node children.


  <xsl:for-each select="key('entity-id','@id')">
        <xsl:value-of select="EntityProps/Name"/>
  </xsl:for-each>

 </included-table>
</xsl:template>

</xsl:stylesheet>

Which outputs the following xml

<Subject_Area>System - Team Structure

<included-table>{5D393595-7786-46CF-9C35-E68DBD5FC979}+00000000</include
d-table>
<included-table>{30882953-C9DF-4911-829E-C1FC00BD8DF8}+00000000</include
d-table>
<included-table>{4618F205-F37B-4350-B520-97E25C1DB431}+00000000</include
d-table>
<included-table>{93B83CDF-8EC0-403B-841B-5A43BDCF9C84}+00000000</include
d-table>
<included-table>{97A23510-C05B-4851-862B-E4F22D87BBBC}+00000000</include
d-table>
<included-table>{C530758F-B0E8-438D-85EC-DF32328008C2}+00000000</include
d-table>
<included-table>{3E248AC3-185F-40F9-85C9-2434D77751AF}+00000000</include
d-table>
<included-table>{AA077968-89A2-40E5-BCF8-CE75D7C52071}+00000000</include
d-table>
</Subject_Area>

Followed by a huge amount of output in the following format:

Which, I suspect, are all descendants of siblings or ancestors of Subject_Area_Groups.


To get around this, in your template for the document node, just push the desired group node:

<xsl:template match="/">
  <xsl:apply-templates select="path/to/the/element/named/Subject_Area_Groups">
</xsl:template>

So far I have studied http://www.w3schools.com/xsl/el_key.asp and
http://www.jenitennison.com/xslt/grouping/muenchian.html and
experimented with many variations but seem to have hit an impasse. I
would be grateful for any help.

Check out any documentation you can find on the built-in template rules.


I hope this helps.

. . . . . . . . . . Ken

--
Upcoming public training: UBL and code lists Oct 1/5; Madrid Spain
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Jul'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

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.