Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 15th, 2008, 08:18 AM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default xslt document function..

Hi,

I am trying to loop through xml files and display the data using xslt..

xsl:template match="test">
    <xsl:variable name="t1" select="document('businessfiles.xml')"/>
      <xsl:for-each select="document(file/@href/parentnav/pagenav)">
        <li>

        I am able to see the files path here like c:\test\file1.xml;c:\test\file2.xml
        by using <xsl:value-of select="."/>

        How can i display the data existing in each file over here...
    <li>

  <xsl:template

any help would be much appreciated...

Cheers,


Reply With Quote
  #2 (permalink)  
Old May 15th, 2008, 08:26 AM
Friend of Wrox
Points: 6,540, Level: 34
Points: 6,540, Level: 34 Points: 6,540, Level: 34 Points: 6,540, Level: 34
Activity: 20%
Activity: 20% Activity: 20% Activity: 20%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,222
Thanks: 0
Thanked 238 Times in 237 Posts
Default

The code
Code:
<xsl:for-each select="document(file/@href/parentnav/pagenav)">
does not make any sense as file/@href selects an attribute and that can't have any child nodes (like parentnav).
I guess you might want
Code:
<xsl:for-each select="document(file/@href)/parentnav/pagenav)">
instead but we can't really tell without knowing how your input XML looks and which data you want to select.

--
  Martin Honnen
  Microsoft MVP - XML
Reply With Quote
  #3 (permalink)  
Old May 15th, 2008, 08:27 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,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I think you have not done a very good job with the cut and paste here, as this bit of XSLT makes no sense.

Assuming that businessfiles.xml contains a list of file elements with href attributes then you can do something like this:

Code:
<xsl:template match="test">
  <xsl:variable name="mainfile" select="document('businessfiles.xml')"/>
  <xsl:for-each select="$mainfile/file">
    <xsl:variable name="file" select="document(@href)"/>
    ? <xsl:value-of select="$file/parentnav/pagenav"/> ?
  </xsl:for-each>
</xsl:template>
/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #4 (permalink)  
Old May 15th, 2008, 01:05 PM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response.
I am really sorry for posting the question in hurry.
As sam wrote, i am trying to loop through the files list exist in businessfiles.xml and display the xml data exist in those files..

Thanks
Maddukuri





Reply With Quote
  #5 (permalink)  
Old May 16th, 2008, 03:30 AM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here are the details..

BusinessFiles.xml

<?xml version="1.0"?>
<NavigationFiles>
  <file href="../../../../content/business/file1.xml"/>
  <file href="../../../../content/business/file2.xml"/>
</NavigationFiles>

file1.xml

<navigation>
  <navpage id="t1">Test</navpage>
  <navpage id="t2">Test2</navpage>
<navigation>


file2.xml

<navigation>
  <navpage id="s1">Test</navpage>
  <navpage id="s2">Test2</navpage>
<navigation>

Hope this helps..

Thanks


Reply With Quote
  #6 (permalink)  
Old May 16th, 2008, 03:40 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,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

We still don't know what you are trying to output, but this should get you going:

Code:
<xsl:template match="test">
  <xsl:variable name="mainfile" select="document('businessfiles.xml')"/>
  <xsl:for-each select="$mainfile/file">
    <xsl:variable name="file" select="document(@href)"/>
    <xsl:for-each select="$file/navigation/navpage">
      Page <xsl:value-of select="@id"/> : <xsl:value-of select="text()"/> 
    </xsl:for-each>
  </xsl:for-each>
</xsl:template>
/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #7 (permalink)  
Old May 16th, 2008, 04:32 AM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Thanks for your prompt response..

I am trying to display the data in xml files as links for sitemap..
Initially trying to display the text and i will extend xml files with url etc..

I am still not able to display @id value..

should i use <navigationfiles> anywhere OR am i missing anything?

Thanks

maddukuri

Reply With Quote
  #8 (permalink)  
Old May 16th, 2008, 06:17 AM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am still working on it,but could not get to display the values.

I am assuming the xml files are in <navigationfiles> root tag, which need to be handled in xsl.

Cheers


Reply With Quote
  #9 (permalink)  
Old May 16th, 2008, 06:31 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,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You seem to be having some very fundamental problems understanding what should be simple xpath expressions.

Yes, there should be a NavigationFiles element in the first for-each:

<xsl:for-each select="$mainfile/NavigationFiles/file">



/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Another Document ( ) Function Question bonekrusher XSLT 2 August 4th, 2006 10:45 AM
Document ( ) Function bonekrusher XSLT 5 August 4th, 2006 08:01 AM
xslt document() function problem with servlet meps XSLT 3 December 20th, 2005 09:34 AM
How to use document() function jacob XSLT 8 November 30th, 2005 07:58 PM
xslt 2.0 document function jkmyoung XSLT 2 November 18th, 2004 02:21 PM



All times are GMT -4. The time now is 01:39 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.