p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: USING TWO XML DOCS


Message #1 by "Pallone, Claudio [KMR-SPC]" <Claudio.Pallone@k...> on Wed, 18 Sep 2002 12:28:19 +0100
Hi Lisa and thanks again for you reply.

Well, let me see if I have understood.

1 - The ThisUserSurvey.xml file will be the look up document and I use 
the document function to call it from my xsl??

(I will be using only one xsl, right???)

2 - I had a look at page 478 of XSLT second Edition but Michael's 
example is different from what I need.

This is what I need:

I have two XML documents - AllSurveys.xml and ThisUserSurvey.xml. The 
ThisUserSurvey.xml document contains only the surveys the this 
particular user can see together with his access codes.

So, I nedd to go through each of the nodes in both documents and if I 
find one that matches I need to output that together with the <Options> 
and <AccessCodes> found only in the ThisUserSurvey.xml file.

So, I think it would be better to pass the ThisUserSurvey.xml as a 
parameter to this specific transformation.

How do I do something like this:

<xsl:for-each select=3D"document('ThisUserSurvey.xml')"> or maybe 
<xsl:for-each select=3D"document('$ThisUserSurvey')">
	check each node in ThisUserSurvey.xml and AllSurveys.xml
		if there nodes that match, copy the nodes to output xml
			add the <Options> and <AccessCodes> from ThisUserSurvey.xml file to 
the output xml as well
		end if
</xsl:for-each>

I would appreciate furter help.

Cheers,

Claudio


AllSurveys.xml

<?xml version=3D3D"1.0" encoding=3D3D"UTF-8"?>
<Surveys>
	<Survey id=3D3D"Eu01">
		<Description>Europa TGI 2001 (Apr00-Mar01) - +Global - =3D
pop</Description>
		<Copyright>BMRB International 2001</Copyright>
		<WeightTitle>Pop</WeightTitle>
		<TotalWeight>1000</TotalWeight>
		<TotalSample>500</TotalSample>
		<LanguageCount>5</LanguageCount>
		<Language id=3D3D"ENG">
			<Description>English (United States)</Description>
		</Language>
		<Language id=3D3D"FRA">
			<Description>French (France)</Description>
		</Language>
		<Language id=3D3D"DEU">
			<Description>German (Germany)</Description>
		</Language>
		<Language id=3D3D"ITA">
			<Description>Italian (Italy)</Description>
		</Language>
		<Language id=3D3D"ESP">
			<Description>Spanish (Traditional Sort)</Description>
		</Language>
	</Survey>
	<Survey id=3D3D"bbs2000p">
		<Description>BBS 2000 - pop</Description>
		<Copyright>BMRB International 2001</Copyright>
		<WeightTitle>Pop</WeightTitle>
		<TotalWeight>1000</TotalWeight>
		<TotalSample>500</TotalSample>
		<LanguageCount>0</LanguageCount>
	</Survey>
	<Survey id=3D3D"PREM00H">
		<Description>PREMIER TGI 2000 - hlld</Description>
		<Copyright>BMRB International 2001</Copyright>
		<WeightTitle>Pop</WeightTitle>
		<TotalWeight>1000</TotalWeight>
		<TotalSample>500</TotalSample>
		<LanguageCount>1</LanguageCount>
		<Language id=3D3D"ENG">
			<Description>English (United States)</Description>
		</Language>
	</Survey>
	<Survey id=3D3D"Eu02r2ESdbp">
		<Description>Europa TGI 2002 Summer Double Base - ES (Apr00-Mar02) - 
=3D
pop</Description>
		<Copyright>BMRB International 2001</Copyright>
		<WeightTitle>Pop</WeightTitle>
		<TotalWeight>1000</TotalWeight>
		<TotalSample>500</TotalSample>
		<LanguageCount>2</LanguageCount>
		<Language id=3D3D"ENG">
			<Description>English (United States)</Description>
		</Language>
		<Language id=3D3D"ESP">
			<Description>Spanish (Traditional Sort)</Description>
		</Language>
	</Survey>

ThisUserSurvey.xml

<?xml version=3D3D"1.0"?>
<Surveys>
	<Survey id=3D3D"PREM00H">
		<Description>Premier TGI 2002</Description>
		<Copyright>Copyright BMRB International 2002</Copyright>
		<RegionCodes/>
		<TotalWeight/>
		<TotalSample/>
		<WeightLabel/>
		<WeightTitle/>
		<WeightUnits/>
		<Language ID=3D3D"">
			<Description/>
		</Language>
		<Options>
			<SupportsAlphaSearch/>
			<Barnardisation/>
			<ReconcileUniverse/>
			<RFModelType/>
		</Options>
		<AccessCodes>
			<CODE>ACR1</CODE>
			<CODE>ACR2</CODE>
			<CODE>ACR3</CODE>
			<CODE>APPL</CODE>
			<CODE>B20X</CODE>
			<CODE>BUSI</CODE>
			<CODE>CARS</CODE>
			<CODE>CCNS</CODE>
			<CODE>CLTH</CODE>
			<CODE>CMAX</CODE>
			<CODE>CNSX</CODE>
			<CODE>DEMO</CODE>
			<CODE>DRNK</CODE>
			<CODE>FINC</CODE>
			<CODE>FNMX</CODE>
			<CODE>HOLS</CODE>
			<CODE>HOME</CODE>
			<CODE>LEIS</CODE>
			<CODE>LIFE</CODE>
			<CODE>LIFX</CODE>
			<CODE>MEDI</CODE>
			<CODE>MOS1</CODE>
			<CODE>MOS2</CODE>
			<CODE>MRBX</CODE>
			<CODE>NTTX</CODE>
			<CODE>OMED</CODE>
			<CODE>PCDX</CODE>
			<CODE>PERS</CODE>
			<CODE>PTKX</CODE>
			<CODE>RETL</CODE>
			<CODE>SBUX</CODE>
			<CODE>SUP1</CODE>
			<CODE>SUP2</CODE>
			<CODE>SUP3</CODE>
			<CODE>TIMX</CODE>
			<CODE>TINY</CODE>
			<CODE>TVVW</CODE>
			<CODE>WJLX</CODE>
			<CODE>XXXX</CODE>
		</AccessCodes>
	</Survey>
	<Survey id=3D3D"Eu01">
		<Description>Europa TGI 2001 (Apr00-Mar01) - +Global - =3D
pop</Description>
		<Copyright>BMRB International 2001</Copyright>
		<RegionCodes/>
		<TotalWeight/>
		<TotalSample/>
		<WeightLabel/>
		<WeightTitle/>
		<WeightUnits/>
		<Language ID=3D3D"">
			<Description/>
		</Language>
		<Options>
			<SupportsAlphaSearch/>
			<Barnardisation/>
			<ReconcileUniverse/>
			<RFModelType/>
		</Options>
		<AccessCodes>
			<CODE>@@@@</CODE>
		</AccessCodes>
	</Survey>
	<Survey id=3D3D"GB00q2h">
		<Description>GB TGI 2000 (Q2 -SUMMER) APR 1999 - MAR 2000 - =3D
hhld</Description>
		<Copyright>BMRB International 2001</Copyright>
		<RegionCodes/>
		<TotalWeight/>
		<TotalSample/>
		<WeightLabel/>
		<WeightTitle/>
		<WeightUnits/>
		<Language ID=3D3D"">
			<Description/>
		</Language>
		<Options>
			<SupportsAlphaSearch/>
			<Barnardisation/>
			<ReconcileUniverse/>
			<RFModelType/>
		</Options>
		<AccessCodes>
			<CODE>@@@@</CODE>
		</AccessCodes>
	</Survey>




----------------------------------------------------------------------

Subject: Re: USING TWO XML DOCS
From: "Lisa Slater Nicholls" <lisa@s...>
Date: Wed, 18 Sep 2002 22:49:36
X-Message-Number: 15

Hi Claudio,

>>
Is it possible to have xslt compare two xml documents and output another 
=3D
xml file with only the surveys that a particular user has permission to 
=3D
see?
<<

Yes, it is possible.  In the situation you describe, the document 
showing
the items the user has permission to see might be referred to as
a "lookup" document.

There are two common ways to make this lookup document available to a
single XSLT as it transforms/filters (the third common way is to pass 
the
document through a *series* of XSLTs):

* -- use the document() function to get a reference to the lookup
document.  This works especially well when the lookup data is saved to
disk.

* -- pass the lookup document as an object to the XSLT, either as a 
global
variable or a global parameter.  This works especially well when the
lookup data is *not* saved to disk, but rather is generated at runtime.  


If the lookup data contains information pertaining to all users and 
their
rights, even if it is not read from a disk cache, then use a global
variable, so it can be compiled into a cached template (rather than read 

in each time you do the transform). 

If, OTOH, the lookup data is dynamically generated to have only the 
rights
of *this* user, then pass it as a parameter to this specific
transformation.

Does this make sense?

>L<


---



BMRB International
http://www.bmrb.co.uk +44 (0)20 8566 5000
____________________________________________________________
This message (and any attachment) is intended only for the recipient and 
may contain confidential and/or privileged material. If you have 
received this in error, please contact the sender and delete this 
message immediately. Disclosure, copying or other action taken in 
respect of this email or in reliance on it is prohibited. BMRB 
International Limited accepts no liability in relation to any personal 
emails, or content of any email which does not directly relate to our 
business.

  Return to Index