[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Accessing two XML files from XSL file

Subject: RE: Accessing two XML files from XSL file
From: "Houghton,Andrew" <houghtoa@xxxxxxxx>
Date: Sat, 9 Jul 2011 23:49:33 -0400
RE:  Accessing two XML files from XSL file
You can pass the URI of the second XML document into the transform and then
use doc-available() and doc() to access the second XML document. A rough
untested sketch:

Command line using saxon: -o out.xml first.xml xsl1.xsl "uri=second.xml"

<xsl:transform>
  <xsl:param name="uri" as="xsd:string?" />
  <xsl:template match="button">
    <button id="{id}" type="button"
style="position:fixed;top:{y}px;left:{x}px;">
      <xsl:value-of select="value" />
    </button>
  </xsl:template>
  <xsl:template match="/">
    <xsl:apply-templates select="xml1/button" />
    <xsl:if test="doc-available($uri)">
      <xsl:variable name="doc" as="document-node()" select="doc($uri)" />
      <xsl:apply-templates select="$doc/xml2/button" />
    </xsl:if>
  </xsl:template>
</xsl:transform>


Hope this helps, Andy.


> -----Original Message-----
> From: Sanjaya Liyanage [mailto:sanjayacl@xxxxxxxxx]
> Sent: Saturday, July 09, 2011 23:21
> To: xsl-list
> Subject:  Accessing two XML files from XSL file
>
> Hi,
>    I want to access two XML files within my XSL file.How can I achieve
> it? Any ideas are welcome
>
> I can access the first.xml file as below because it has the reference
> to XSL file(xsl1.xsl).
>
>    <xsl:for-each select="xml1/button">
>    <button id="{id}" type="button"
> style="position:fixed;top:{y}px;left:{x}px;"><xsl:value-of
> select="value"/></button>
>    </xsl:for-each>
>
> I want to have something like below which is working which access the
> second.XML
>
>    <xsl:for-each select="xml2/button">
>    <button id="{id}" type="button"
> style="position:fixed;top:{y}px;left:{x}px;"><xsl:value-of
> select="value"/></button>
>    </xsl:for-each>
>
> first.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet type="text/xsl" href="xslt1.xsl"?>
>
> <xml1>
> <button>
> <id>btn1</id>
> <x>225</x>
> <y>450</y>
> <value>Submit</value>
> </button>
> </xml1>
>
> second.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <xml2>
> <button>
> <id>btn2</id>
> <x>325</x>
> <y>550</y>
> <value>Submit</value>
> </button>
> </xml2>
>
> Thank you
> Sanjaya Liyanage

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.