Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Newbie: XSLT: How do pull in info from another XML file?

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 5/15/2009 12:11:00 PM
lister wrote:

> I am playing with XSLT to transform an XML file to HTML for rendering.
> I would like to pull in information from another lookup XML file but I
> can't find out how to address it in the stylesheet. XPath always seems
> to refer to the current file.

In XSLT 1.0 you can use the 'document' function which is powerful but as 
its easiest is used as e.g.
   document('file.xml')
See http://www.w3.org/TR/xslt#document

With XSLT and XPath 2.0 there is also the 'doc' function, see 
http://www.w3.org/TR/xpath-functions/#func-doc


Note also that XSLT allows you to pack data into the stylesheet e.g.

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0"
   xmlns:data="http://example.com/2009/mydata"
   exclude-result-prefixes="data">

<data:data>
   <lookup>
     <map key="01" value="January"/>
     <map key="02" value="February"/>
     ...
   </lookup>
</data:data>

<xsl:variable name="map" select="document('')/*/data:data/loopup/map"/>

</xsl:stylesheet>

but separating it into a second document is of course possible.


-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/


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