Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] New doubt !

From: "Aron Bock" <aronbock@----------->
To:
Date: 5/3/2005 5:19:00 AM
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: [xsl] New doubt !
Date: Tue, 3 May 2005 08:29:11 +0530

Hi all,



I am glad I came across this group.



I need to transform a XML to other structure XML using XSLT.



Fine I have done that quite well according to my projects needs.



Now the problem is ....



When an input element of tag



<RetailStoreID>Bangalore Central</RetailStoreID> is encountered in the
input XML ( Please note that At this stage since this XML is genreated
from some transaction handling code, I will not know in advance what
store will appear in that tag . But eventually all of them are assumed
to be in some lookup table that i will explain now ) , my XSLT should
be able to refer to some other XML that stores in this format

Retail Store Name                      ID
===========================
Bangalore central                  2345
Walmart                               4567

like that ....



I tried using the document("reatilstoreids.xml") what to put in the
query after this is beating me ...

When Walmart is encountered i need to get 4567 and if Bangalore
central i shud get 2345 through some testing so that thats is
displayed in the Output XML . Just help me on how to get ids of the
names encountered in the input XML in this other XML called
RetailerStoreIDs.xml

_________________________________________________________________

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


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