Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 25th, 2008, 06:04 AM
Authorized User
Join Date: Jul 2008
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple input xml / get data from other xml file

I am unable to get the Date value. I have multiple input xml file, i am unable to load other xml inbetween such as

<getdata from file1, getdata from file2, again getdata from file1>

[u]Command:</u> $xalan Input.xml fileXSL.xsl

[u]Actual Output: </u> FORMHDR|1.85|Mr.|????????||
[u]Expected Output:</u> FORMHDR|1.85|Mr.|20080428||

Please find the xml and xsl file as follows,

<?xml version="1.0" encoding="UTF-8"?>
<Part File='INV24.2302.xml' LinkType='REL' DocType='INV' Format='XML'/>
<Part File='ADDR24.2302.xml' LinkType='REL' DocType='ADD' Format='XML'/>

<?xml version='1.0' encoding="UTF-8"?>
<Date Type="INV" Date="20080428"/>
<Date Type="START" Date="20060101" />
<Date Type="END" Date="20080427" HH="23" MM="59" SS="59" />

<?xml version='1.0' encoding="UTF-8"?>
<Document Sender="Eureka Communications" Id="080428BA00000000910" BAId="BA0000000091">
<AddressPage xml:lang="EN">
<BillAcc Desc="Nm_24" PayMeth="1Cash" BillMedium="L1PDF" CopyNo="1" State="">
<Customer Id="1.85" SocSecNo="" DrivLicNo=""/>
<Addr Name="" City="Frankfurt" Zip="96745" Country="Germany" Line1="Mr." Line2="Jim Collins" Line3="" Line4="Herriot Street 1" Line5="96745 Frankfurt" Line6="Germany" SortCrit="0000000000000000000000000000000000000000 " />

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE stylesheet [
<!ENTITY space "<xsl:text> </xsl:text>">
<!ENTITY tab "<xsl:text>#9;</xsl:text>">
<!ENTITY sep "<xsl:text>|</xsl:text>">
<!ENTITY cr "<xsl:text>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" version="1.0">

<xsl:output method="text"/>

<xsl:template match="/">
    <xsl:for-each select="/Envelope/Part">
            <xsl:apply-templates select="document(@File)/Document/AddressPage/BillAcc" mode="FORMHDR"/>

<xsl:template match="/Document/AddressPage/BillAcc" mode="FORMHDR">
    <xsl:param name="Sheet"/>
    <xsl:value-of select="Customer/@Id"/>&sep;
    <xsl:value-of select="Addr/@Line1"/>&sep;
    <xsl:value-of select="document(@File)/Document/Invoice/Date[@Type='INV']/[u]@Date</u>"/>&sep;
    <xsl:value-of select="Customer/@SocSecNo"/>&sep;

Old July 25th, 2008, 06:23 AM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

In the section highlighted in red the current context is the BillAcc element. This element does not have @File attribute, therefore your document(@File) method will not load anything.

If you have only two documents to load then define some global variables to load them once:

<xsl:variable name="InvDoc" select="document(/Envelope/Part[@DocType='INV']/@File)"
<xsl:variable name="AddDoc" select="document(/Envelope/Part[@DocType='ADD']/@File)"

/- Sam Judson : Wrox Technical Editor -/
Old July 25th, 2008, 06:33 AM
Authorized User
Join Date: Jul 2008
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for your reply.

I tried , but no luck Sam Judson

    <xsl:value-of select="document(/Envelope/Part/@File)/Document/Invoice/Date[@Type='INV']/@Date"/

I can't define the file in variable... because the filename will be dynamic(auto genearation).
Old July 25th, 2008, 06:59 AM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

That still wont work. When you refer to "/" from within the context of the BillAcc element you are traversing that document to its root, i.e. the root of /Document/AddressPage/BillAcc. This xml tree does not have an Envelope element.

If you want to refer to your input document from within another document context then create a global variable like so:

<xsl:variable name="root" select="/"/>

And then refer to this like so:

<xsl:value-of select="document($root/Envelope/Part/@File)"/>

/- Sam Judson : Wrox Technical Editor -/

Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.net, adding XML data to an existing XML file saikoboarder XML 11 April 17th, 2008 04:19 PM
How to ignore namespaces in input xml file hanifa XSLT 2 February 14th, 2007 04:14 AM
One XML to Multiple XML file dineshrout XSLT 3 May 11th, 2006 12:24 PM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
Extract data and create xml for input dhol General .NET 1 February 2nd, 2005 03:01 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.