|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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, |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
Quote:
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. |
|
#4
|
||||
|
||||
|
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>
|
|
#5
|
||||
|
||||
|
Quote:
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:
Thanks for the help. ![]() |
|
#6
|
|||
|
|||
|
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"?> |
|
#7
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSLT - document function, string+$var+string...? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|