help on function document()
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Sun Apr 05, 2009 9:52 pm
help on function document()
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.

-
- Site Admin
- Posts: 2097
- Joined: Thu Jan 09, 2003 2:58 pm
Re: help on function document()
You need to put the logic inside the variable and decide its value, like below
Best Regards,
George
Code: Select all
<xsl:variable name="lang_file">
<xsl:choose>
<xsl:when test="$lang=''en">english.xml</xsl:when>
<xsl:when test="$lang=''fr">french.xml</xsl:when>
<xsl:otherwise>english.xml</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Best Regards,
George
George Cristian Bina
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service