Re: [xsl] New user issue: use of Muenchian method

Subject: Re: [xsl] New user issue: use of Muenchian method
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 21 Sep 2007 11:10:19 -0400
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-area name="System - Team Structure">
                        <included-table name="team"/>
                        <included-table name="team_level"/

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_Area id="{661CB799-677D-4359-A128-46DC5078D9D5}+00000000"
name="System - Team Structure">
    <Name>System - Team Structure</Name>

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

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

<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
<xsl:output method="xml" indent="yes"/>

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

<xsl:template match="/">

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 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.

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

<xsl:template match="Subject_Area">
  <xsl:value-of select="@name"/>

  <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"/>



Which outputs the following xml

<Subject_Area>System - Team Structure


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">

So far I have studied and 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.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Jul'07
Legal business disclaimers:

Current Thread