|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: New doubt !
Bharat, 2 people have answered to this by now, but I'm responding
nonetheless because IMO those responses were either too involved or
needlessly wordy.
You already know that external XML files may be accessed via the document() function. Thus, if you have an XSL file with document('lookups.xml') will access an XML file called 'lookups.xml' in the same folder as the XSL. Note that document('/') returns you the input XML document if you wanted that for some reason, and document('') returns the XSL document itself. In every case, ceteris paribus, the document() function returns the root of the referenced document. You then navigate this simply by applying XPath expressions. For example, assume the lookup file is as follows: lookups.xml ======= <stores> <store name="Bangalore Central" ID="2345"/> <store name="Walmart" ID="4567"/> </stores> That your input XML file is as follows:
=======
<foo>
<store>
<RetailStoreName>Bangalore Central</RetailStoreName>
</store
</foo>And that you wanted to convert this to: ======= <foo>
<store>
<name>Bamgalore Central</name>
<id>2345>/id>
</store>
</foo>You'd create an XSL file with the usual trappings, then do this: <!-- Since you expect to refer to lookups.xml many times, it's a good idea to create a top-level variable to refer to it --> <xsl:variable name="doc-lookups" select="document('lookups.xml')"/> <!-- the store-specific template; notice we traverse the lookup document like any other document --> <xsl:template match="store"> <store> <name><xsl:value-of select="RetailStoreName"/></name> <id><xsl:value-of select="$doc-lookups/stores/store[@name = RetailStoreName]/@name"/></id> </store> </xsl:template> Regards, --A PS: Please try to use a more descriptive subjectline. "How do I traverse an external XML document?" would be more useful to people coming after you, than the one in this post. From: Bharat Shetty <bharat.shetty@xxxxxxxxx> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: New doubt ! Date: Tue, 3 May 2005 08:29:11 +0530 _________________________________________________________________ On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








