help on function document()
Posted: Sun Apr 05, 2009 10:13 pm
Hi,
I've created some XML files containing the days of the week in different languages having the same structure.
Example: english.xml
<days>
<day>monday</day>
<day>tuesday</day>
<day>wednesday</day>
.
.
</days>
I also created an XML with that I would like to transform using XSLT with an HTML output.In my XSL file,I would like make a reference to my external XML files containing the days of the week,I wrote the following code:
1.<xsl:variable name="lang_file"/>
2.<xsl:if test="$lang='en'"><!--lang is a parameter of my xsl template-->
3.$lang_file="english.xml"
4.</xsl:if>
5.<td><xsl:value-of select="document($lang_file)/days/day[1]"/></td>
I encounter 2 problems:
-at the 3rd line,I have no idea of how to wrap the instruction "$lang_file="english.xml" into and xsl tag,is the operation permitted in XSLT?
I want to avoid creating a variable for every language file for example:
<xsl:variable name="lang_file_fr" select="'french.xml'"/>
<xsl:variable name="lang_file_en" select="'english.xml'"/>
.
.etc...
Even when I do so,I still there a problem at line 5,it seems that the document() function can't take a variable as a parameter,the documentation says it takes an URI as parameter(ref:http://www.w3schools.com/Xsl/func_document.asp)
How can I solve this 2 problems?Is there any other solution(may be simpler)?
Thanks for assistance.
I've created some XML files containing the days of the week in different languages having the same structure.
Example: english.xml
<days>
<day>monday</day>
<day>tuesday</day>
<day>wednesday</day>
.
.
</days>
I also created an XML with that I would like to transform using XSLT with an HTML output.In my XSL file,I would like make a reference to my external XML files containing the days of the week,I wrote the following code:
1.<xsl:variable name="lang_file"/>
2.<xsl:if test="$lang='en'"><!--lang is a parameter of my xsl template-->
3.$lang_file="english.xml"
4.</xsl:if>
5.<td><xsl:value-of select="document($lang_file)/days/day[1]"/></td>
I encounter 2 problems:
-at the 3rd line,I have no idea of how to wrap the instruction "$lang_file="english.xml" into and xsl tag,is the operation permitted in XSLT?
I want to avoid creating a variable for every language file for example:
<xsl:variable name="lang_file_fr" select="'french.xml'"/>
<xsl:variable name="lang_file_en" select="'english.xml'"/>
.
.etc...
Even when I do so,I still there a problem at line 5,it seems that the document() function can't take a variable as a parameter,the documentation says it takes an URI as parameter(ref:http://www.w3schools.com/Xsl/func_document.asp)
How can I solve this 2 problems?Is there any other solution(may be simpler)?
Thanks for assistance.
