Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Joining xml documents on the fly

From: "James A. Robinson" <jim.robinson@--------.--->
To: xsl-list@-----.------------.---
Date: 6/4/2009 3:45:00 PM
> I want to break this into two groups based on the current project_id.
> So if I'm viewing project_id=1
> I want two groups of people
> 
> Project Staff:
> <people>
>     <staff staff_id="123456789" alpha_key="A" sort_key="AberyBrian">
>         <display_name>Brian H Abery</display_name>
>     </staff>
> </people>
> 
> Non-Project-Staff
> <people>
>     <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>
> 
> I've got the following variables in my document:
> <xsl:variable name="staff" select="document($ref_staff)/people"/>
> <xsl:variable name="staff_roles" 
> select="document($ref_project_staff_role)/project_staff_roles/project_staff_role[@role_id='staff']"/>
> <xsl:variable name="project_staff" 
> select="$staff_roles[@project_id=$[project_id]/staff"/>
> <xsl:variable name="non_project_staff" select="?????"/>
> 
> How do I even go about thinking about this? I've tried googling it but I 
> have no idea what to search on. I've tried various iterations of keys, 
> etc but I just can't get it.

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@s...
Stanford University HighWire Press      http://highwire.stanford.edu/
+1 650 7237294 (Work)                   +1 650 7259335 (Fax)

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent