Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old July 25th, 2008, 06:04 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple input xml / get data from other xml file

Hi,
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,

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

[u]INV24.2302.xml:</u>
<?xml version='1.0' encoding="UTF-8"?>
<Document>
<Invoice>
<Date Type="INV" Date="20080428"/>
<Date Type="START" Date="20060101" />
<Date Type="END" Date="20080427" HH="23" MM="59" SS="59" />
</Invoice>
</Document>

[u]ADDR24.2302.xml:</u>
<?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 " />
</BillAcc>
</AddressPage>
</Document>


[u]fileXSL.xsl:</u>
<?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: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:for-each>
</xsl:template>

<xsl:template match="/Document/AddressPage/BillAcc" mode="FORMHDR">
    <xsl:param name="Sheet"/>
    <xsl:text>FORMHDR</xsl:text>&sep;
    <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;
</xsl:template>

</xsl:stylesheet>
  #2 (permalink)  
Old July 25th, 2008, 06:23 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
  #3 (permalink)  
Old July 25th, 2008, 06:33 AM
Authorized User
 
Join Date: Jul 2008
Location: , , .
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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).
  #4 (permalink)  
Old July 25th, 2008, 06:59 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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.