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 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Chris LongfieldSubject: Using two XML docs in one stylesheet
Author: Chris Longfield
Date: 21 May 2001 10:42 AM

Here is a simple question:
How do I use two different documents with one stylesheet to produce another XML
document?
For example, say I have produced a sorted list of id's in some XML format, and now I
want to search a tree of items that correspond to these id's.

I would probably want to apply the stylesheet to the document that has the in-depth
information, so the id set might come in as a parameter. (Is this the right way?)

If so, how do I apply an xpath expression to some parameter that holds a node set?

xsl:foreach select=???

If not, what is the best way to do it?

Also, I am testing out 3.0 (I have rc3 and some 3.0 version of stylus studio) Does this change my approach?

Chris Longfield
clongfield@merrilhall.com

Posttop
Rudolf P WeinmannSubject: Using two XML docs in one stylesheet
Author: Rudolf P Weinmann
Date: 02 Jun 2001 03:18 AM
Chris

One way is the use of xsl:key
First you define a key at the top level of the stylesheet:
{xsl:key name="text-to-be-fetched" select="*[@ID]" use="@ID"/}

Now you can use the key() function. 
A key is always applied to the current context.
So, the only thing to do is to change the context.
This can be done using {xsl:for-each}

{xsl:variable name="LookupID" select="AnID-ofTheElementYouWantToLookup"/}

{xsl:for-each select="document('YourLookupDocument')"}
  {xsl:value-of select="key('text-to-be-fetched',$LookupID)"/}
{/xsl:for-each}

hope this helps.
Rudolf P. Weinmann
Senior Consultant
Innovation Process Technology Inc.
http://www.ipt.ch

From: "Vittorio Viarengo" 

Chris,

I just did something similar (with the help of our talented engineering team
of course :) but I'm not sure it is the same. Anyway, here it is

I needed to use a string table (modeled in XML and saved into a file called
string_table_english.xml which contains an ID attribute for quick lookup of
strings) from within a stylesheet front_page.xsl applied to another XML file
(news.xml).

In front_page.xsl I used this instruction to load the string table.

{xsl:variable name="st"
select="document('pictures:/string_table_engligh.xml')/STRING_TABLE/STRING"/
}

this creates a node set containing all the strings from the
'string_table_engligh.xml' file.

Then I used the string table inside the stylesheet this way

	{xsl:value-of select="$st[@ID='there_are']"/}

In this way you load the data at the beginning and then you use it inside
the stylesheet. Having the ID declared an as ID element should speed up the
look up.
You can also change the document you are including at any given execution of
the stylesheet by using a parameter in the document function

{xsl:variable name="string_table_file"}
	{xsl:choose}
		{xsl:when
test="$language='English'"}pictures:/string_table_english.xml{/xsl:when}
		{xsl:when
test="$language='Italiano'"}pictures:/string_table_italian.xml{/xsl:when}
	{/xsl:choose}
{xsl:variable name="st"
select="document($string_table_file)/STRING_TABLE/STRING"/}


Another way of doing it is to use the document function every time you need
to access data from the other file.

	{xsl:value-of
select="document('pictures:/string_table_english.xml')/STRING_TABLE/STRING[@
ID='there_are']"/}


Ciao

Vittorio


On 5/21/01 10:42:28 AM, Chris Longfield wrote:
>
>Here is a simple question:
>How do I use two different
>documents with one stylesheet
>to produce another XML
>document?
>For example, say I have
>produced a sorted list of id's
>in some XML format, and now I
>want to search a tree of items
>that correspond to these id's.
>
>I would probably want to apply
>the stylesheet to the document
>that has the in-depth
>information, so the id set
>might come in as a parameter.
>(Is this the right way?)
>
>If so, how do I apply an xpath
>expression to some parameter
>that holds a node set?
>
>xsl:foreach select=???
>
>If not, what is the best way
>to do it?
>
>Also, I am testing out 3.0 (I
>have rc3 and some 3.0 version
>of stylus studio)  Does this
>change my approach?
>
>Chris Longfield
>clongfield@merrilhall.com



 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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.