XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 19th, 2004, 01:27 PM
Covenent Covenent is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 17 Covenent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
XSLT - document function, string+$var+string...?

I have a series of XML files that represent courses. They look something like the simplified version below, but each files root node will have a different department attribute:

Code:
<course id="a1" department="art">
 <name>My Course</name>
 <description>This is a description of my course.</description>
</course>


Now I want to use the document function to load the department XML file so that I can provide additional information in my output. The URI of this file is made up like so:

Code:
D:/departments/variableName/index.xml


I presumed I could just concat a string, the variable, and another string and pass that as the argument to the document function, but it does'nt work (see code below).

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<!-- Global Variables -->
	<xsl:variable name="myVar" select="/course/@department" />
	<xsl:variable name="departmentOverview" select="document('../../departments/'+$myVar+'/index.xml')" />
</xsl:stylesheet>


I have also tried a bunch of bizarre method involving switching variables around, and converting them to strings using the string function, but none of them worked.

As anyone got any suggestions? I'm stumped.

Thanks for any help,

Reply With Quote
  #2  
Old September 19th, 2004, 03:03 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,569 jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 22 h 42 m 51 sec
Reputation Power: 835
Oh it's been a while since I've played with XSL, but try this:
Code:
<xsl:variable name="departmentOverview" select="document('../../departments/{/course/@department}/index.xml')" />
__________________
# Jeremy

Explain your problem instead of asking how to do what you decided was the solution.

Reply With Quote
  #3  
Old September 19th, 2004, 03:32 PM
Covenent Covenent is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 17 Covenent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by jharnois
Oh it's been a while since I've played with XSL, but try this:
Code:
<xsl:variable name="departmentOverview" select="document('../../departments/{/course/@department}/index.xml')" />



Nope that didn't work. I tried to test if it was working (as explained here ), but from what I can tell the curly brackets are just being interpreted as part of the string.

Thanks for the suggestion though.

Reply With Quote
  #4  
Old September 19th, 2004, 05:28 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,569 jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 22 h 42 m 51 sec
Reputation Power: 835
Do you need to create the variable? If you use the value of departmentOverview directly as an attribute in the resulting HTML, it should work. What I mean:
Code:
<xsl:stylesheet ...>
<a href="../../departments/{/course/@department}/index.xml">Your link's text.</a>
</xsl:stylesheet>

Reply With Quote
  #5  
Old September 19th, 2004, 07:21 PM
Covenent Covenent is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 17 Covenent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by jharnois
Do you need to create the variable? If you use the value of departmentOverview directly as an attribute in the resulting HTML, it should work. What I mean:
Code:
<xsl:stylesheet ...>
<a href="../../departments/{/course/@department}/index.xml">Your link's text.</a>
</xsl:stylesheet>


I need to load the department XML file that the current course XML file is related to so that I can output extra information, so the above won't work.

Simply put what I am trying is this (but where the URI of the XML file is determined by the department attribute of the source trees root node):

Code:
<!-- Global Variables -->
<xsl:variable name="departmentOverview" select="document('D:/root node's department attribute/index.xml')" />

<xsl:template match="/">
 The name of the department that this course belongs to is: <xsl:value-of select="$departmentOverview/department/name" />.
 The name of the coordinator of the department that this course belongs to is: <xsl:value=of select="$departmentOverview/department/coordinator" />
</xsl:template>.


Would result in this output:

Quote:
The name of the department that this course belongs to is: Art & Ceramics.
The name of the coordinator of the department that this course belongs to is: Joe Bloggs.


Thanks for the help.

Reply With Quote
  #6  
Old September 20th, 2004, 11:50 AM
rguilbault rguilbault is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 30 rguilbault User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 18 sec
Reputation Power: 5
Hi, is it actually possible to do what you're trying to do? I'm curious, because I'd LOVE to do something similar this way -- I had to use javascript and perform the translations in an html page...

Question -- why not just link the stylesheet from the XML data files? -- each file will need to include the line: <?xml-stylesheet type="text/xsl" href="template.xsl"?>

Reply With Quote
  #7  
Old September 20th, 2004, 07:58 PM
Covenent Covenent is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 17 Covenent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I don't if it is possible, thats why I asked. I would presume it is possible as it isn't exactly anything complex that I am trying here, simply just adding a variable to a string in an XPath expression.

I suppose I could create several stylesheets one for each department, but the idea was to just have the one stylesheet and keep everything nice and neat.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSLT - document function, string+$var+string...?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT