XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Cynthia van BovenSubject: Performance xsl:for each and need for xsl:key instruction?
Author: Cynthia van Boven
Date: 27 Mar 2009 05:30 AM
Good morning to you all,

I made some XSLT code to join two xml files. The first files contains projects, the second file contains project members. The project members need to be joined with the first file as tag somewhere in the project code. Now I made two pieces of code, the first one works but is performing very badly. In the second code I trief to solve this by using a xsl:key instruction. The second doesn't work however: could the reason be that ProjectNr should be a top level node?

Part of file 1:
<projecten><etl_projecten><ProjectNr>100/10001</ProjectNr><ParentProject></ParentProject><Description>fonds voor uitzendingen</Description><IDCustomer>200368</IDCustomer>...........</etl_projecten>

Part of file 2:
<?xml version="1.0" encoding="utf-8"?>
<behandelteams>
<etl_behandelteams>
<ProjectNr>100/10001</ProjectNr>
<Projectlid>10</Projectlid>
</etl_behandelteams>
<etl_behandelteams>
<ProjectNr>100/10001</ProjectNr>
<Projectlid>595</Projectlid>
</etl_behandelteams>
<etl_behandelteams>
<ProjectNr>100/10003</ProjectNr>
<Projectlid>595</Projectlid>
</etl_behandelteams>

Part of xslt 1:
<Members>
<xsl:variable name="ProjA" select="ProjectNr"/>
<xsl:for-each select="document('file:///E:/Klanten/Cordaid/Conversie/Behandelteams/etl_behandelteams_total.xml')/behandelteams/etl_behandelteams">
<xsl:variable name="ProjB" select="ProjectNr"/>
<xsl:variable name="Lid" select="Projectlid"/>
<xsl:if test="$ProjA=$ProjB">
<Member>
<Resource>
<xsl:attribute name="number">
<xsl:value-of select="Projectlid"/>
</xsl:attribute>
</Resource>
</Member>

Part of xslt 2:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key
name="ProjectNumber"
match="projecten/etl_projecten"
use="ProjectNr"/>
<xsl:template match="/">
<eExact>
<Projects>
<xsl:for-each select="projecten/etl_projecten">
<Project>
......

<Members>
<Member>
<Resource>
<xsl:variable name="ProjA" select="ProjectNr"/>
<xsl:for-each select="document('file:///E:/Klanten/Cordaid/Conversie/Behandelteams/etl_behandelteams_total.xml')">
<xsl:variable name="ProjB" select="key('ProjectNumber',$ProjA)"/>
<xsl:attribute name="number">
<xsl:copy-of select="$ProjB"/>
</xsl:attribute>
</xsl:for-each>
</Resource>
</Member>
</Members>

Thanks for your help!


Cynthia

Postnext
James DurningSubject: Performance xsl:for each and need for xsl:key instruction?
Author: James Durning
Date: 27 Mar 2009 01:32 PM
The key is only applied on the source document, not the extra one referenced by the document function.

You may want to rethink how you're applying your xslt. Does the order of the projects matter? What is the relationship between file 1 and file 2? Is it a 1-1 mapping? 1-0 or 1? etc...

Posttop
Cynthia van BovenSubject: Performance xsl:for each and need for xsl:key instruction?
Author: Cynthia van Boven
Date: 29 Mar 2009 07:43 AM
Hi James,

Solved it by making the following xquery. I find it sometimes difficult when to choose for an xquery and when to go for xslt. Comparing results xquery is way better for this particular case:

<eExact>
<Projects>
{
for $etl_projecten in doc('file:///e:/Klanten/Cordaid/Conversie/Projecten/5maart/etl_projecten_part1of7.xml')/projecten/etl_projecten
return
<Project>
{$etl_projecten/ProjectNr/text()}
<Members>

{for $etl_behandelteams in doc('file:///e:/Klanten/Cordaid/Conversie/Behandelteams/etl_behandelteams_part1of6.xml')/behandelteams/etl_behandelteams
where $etl_behandelteams/ProjectNr=$etl_projecten/ProjectNr
return
<Member>
{$etl_behandelteams/Projectlid/text()}
</Member>
}
</Members>
</Project>
}
</Projects>
</eExact>

Thanks for your help,


Cynthia

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.