Re: [xsl] Multiple relationships

Subject: Re: [xsl] Multiple relationships
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 6 May 2002 15:05:07 +0100
Hi Craig,

> I need to select the relationship type that fits some rules and
> display only that relationship and the party information that goes
> with it. Any suggestions as to how to code the XSL to do this?

You haven't given many details, so it's a bit difficult to answer your

What do you mean by "the relationship type that fits some rules"? Do
you mean that you have the value for the RelationRoleCode for the
Relation object? Or some other combination of information? Without
knowing the details, I'd suggest that you use a key to quickly get to
the Relation based on whatever the rules are. So for example if you
need to get to it based on its RelationRoleCode, then use:

<xsl:key name="relations" match="Relation" use="RelationRoleCode" />

Then you can get all the Relation objects that have the
RelationRoleCode 'Owner', for example, using:

  key('relations', 'Owner')

If, say, you had that value as a $relationRole stylesheet parameter:

<xsl:param name="relationRole" />

you could apply templates to the relevant Relations using:

<xsl:template match="/">
  <xsl:apply-templates select="key('relations', $relationRole)" />

Then you need to have a template that prints out information about the
relation. I guess that the "RelatedObjectID" attribute on a Relation
is a reference to the id of a Party element elsewhere in the document?
If so, then you should have another key for Party elements:

<xsl:key name="parties" match="Party" use="@id" />

So given that you're processing a Relation you can get hold of the
Party element representing the related object using:

  key('parties', @RelatedObjectID)

So you might have a couple of templates -- one for Relation elements,
and one for Party elements -- that look like:
<xsl:template match="Relation">
  <h3><xsl:value-of select="RelationRoleCode" /></h3>
    <dt><xsl:value-of select="RelatedObjectType" /></dt>
      <xsl:apply-templates select="key('parties', @RelatedObjectID)"/>

<xsl:template match="Party">
  <xsl:value-of select="FullName" />
    <xsl:for-each select="Line1 | Line2 | Line3">
      <xsl:value-of select="." />,<br />
    <xsl:value-of select="City" />,<br />
    <xsl:value-of select="AddressState" />
    <xsl:text> </xsl:text>
    <xsl:value-of select="Zip" />

You probably want to do the same kind of thing with the
OriginatingObjectID attribute, but it doesn't seem to be holding the
id of a Party (from the sample that you sent), so perhaps you need
something different there. It's hard to tell.

I hope that's given you some ideas. Do come back with some more
details (a sample of the output you want, for example, and the XSLT
that you've tried) if you run into problems or if my guesses above are
way off.



Jeni Tennison

 XSL-List info and archive:

Current Thread