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 May 15th, 2008, 08:18 AM
Registered User
 
Join Date: May 2008
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,


 
Old May 15th, 2008, 08:26 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 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
 
Old May 15th, 2008, 08:27 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
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 -/
 
Old May 15th, 2008, 01:05 PM
Registered User
 
Join Date: May 2008
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





 
Old May 16th, 2008, 03:30 AM
Registered User
 
Join Date: May 2008
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


 
Old May 16th, 2008, 03:40 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
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 -/
 
Old May 16th, 2008, 04:32 AM
Registered User
 
Join Date: May 2008
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

 
Old May 16th, 2008, 06:17 AM
Registered User
 
Join Date: May 2008
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


 
Old May 16th, 2008, 06:31 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
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 -/





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 10:34 AM
How to use document() function jacob XSLT 8 November 30th, 2005 08:58 PM
xslt 2.0 document function jkmyoung XSLT 2 November 18th, 2004 03:21 PM





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