Re: [xsl] Joining xml documents on the fly

Subject: Re: [xsl] Joining xml documents on the fly
From: Joelle Tegwen <tegwe002@xxxxxxx>
Date: Thu, 04 Jun 2009 11:03:23 -0500
I always forget to mention I'm on xsl 1.0. The role_id created a "distinct" set because everyone is automatically staff.

Thanks
Joelle

I don't know how important @role_id as you indicate in your code above
is to your solution, but just looking at it from the point of view of
set operations on staff ids and project ids:

    <!-- staff ids of those people involved in project $project-id -->
    <xsl:variable name="project-staff"
      select="distinct-values($projects/project_staff_roles/project_staff_role[@project_id eq $project-id]/@staff_id)" />

    <!-- staff ids of all people not involved in project $project-id -->
    <xsl:variable name="non-project-staff"
      select="distinct-values($people/people/staff[@staff_id != $project-staff]/@staff_id)" />

e.g. (you can replace the variables with document() calls, of course),

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:xs="http://www.w3.org/2001/XMLSchema";
exclude-result-prefixes="xs"
version="2.0">
<xsl:variable name="people">
<people>
<staff staff_id="123456789" alpha_key="A" sort_key="AberyBrian">
<display_name>Brian H Abery</display_name>
</staff>
<staff staff_id="987654321" alpha_key="A" sort_key="AlbusDeb">
<display_name>Deb Albus</display_name>
</staff>
<staff staff_id="456321789" alpha_key="A" sort_key="AltmanJason">
<display_name>Jason R Altman</display_name>
</staff>
</people>
</xsl:variable>
<xsl:variable name="projects">
<project_staff_roles>
<project_staff_role project_id="1" staff_id="123456789" role_id="staff">
<staff staff_id="123456789" alpha_key="A" sort_key="AberyBrian">
<display_name>Brian H Abery</display_name>
</staff>
</project_staff_role>
<project_staff_role project_id="1" staff_id="123456789" role_id="director">
<staff staff_id="123456789" alpha_key="A" sort_key="AberyBrian">
<display_name>Brian H Abery</display_name>
</staff>
</project_staff_role>
<project_staff_role project_id="2" staff_id="987654321" role_id="staff">
<staff staff_id="987654321" alpha_key="A" sort_key="AlbusDeb">
<display_name>Deb Albus</display_name>
</staff>
</project_staff_role>
</project_staff_roles>
</xsl:variable>


<xsl:output indent="yes" />

  <xsl:template match="/">
    <xsl:param name="project-id" select="'1'" />

    <!-- staff ids of those people involved in project $project-id -->
    <xsl:variable name="project-staff"
      select="distinct-values($projects/project_staff_roles/project_staff_role[@project_id eq $project-id]/@staff_id)" />

    <!-- staff ids of all people not involved in project $project-id -->
    <xsl:variable name="non-project-staff"
      select="distinct-values($people/people/staff[@staff_id != $project-staff]/@staff_id)" />

    <people type="Project Staff" project_id="{$project-id}">
      <xsl:copy-of select="$people/people/staff[@staff_id = $project-staff]" />
    </people>

<people type="Non-Project Staff" project_id="{$project-id}">
<xsl:copy-of select="$people/people/staff[@staff_id = $non-project-staff]" />
</people>
</xsl:template>


</xsl:stylesheet>

produces

<people type="Project Staff" project_id="1">
   <staff staff_id="123456789" alpha_key="A" sort_key="AberyBrian">
      <display_name>Brian H Abery</display_name>
   </staff>
</people>
<people type="Non-Project Staff" project_id="1">
   <staff staff_id="987654321" alpha_key="A" sort_key="AlbusDeb">
      <display_name>Deb Albus</display_name>
   </staff>
   <staff staff_id="456321789" alpha_key="A" sort_key="AltmanJason">
      <display_name>Jason R Altman</display_name>
   </staff>
</people>


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - James A. Robinson jim.robinson@xxxxxxxxxxxx Stanford University HighWire Press http://highwire.stanford.edu/ +1 650 7237294 (Work) +1 650 7259335 (Fax)

Current Thread