473,795 Members | 2,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xsl:include with a computed filename

I'm trying to do internationalis ation by using xsl:include to include
a different file depending on the locale setting, and I'm completely
failing.

I've tried several different approaches:
<xsl:include href="concat( 'i18n-', $locale, '-include.xslt)"/>

fails with XSLT compile error: FileNotFoundExc eption
---------------------
Could not find file 'C:\Projects\AD L\transforms01\ concat( 'i18n-',
$locale, '-include.xslt)'.
<xsl:include>
<xsl:attribut e name="href">
<xsl:value-of select="concat( 'i18n-', $locale, '-include.xslt)"/>
</xsl:attribute>
</xsl:include>

fails with 'Missing mandatory attribute'
<xsl:param name="i18n-include" select="i18n-en-GB-include.xslt"/>

<xsl:include href="$i18n-include"/>

fails with XSLT compile error:.FileNotF oundException
---------------------
Could not find file 'C:\Projects\AD L\transforms01\ $i18n-include'.
xsl:choose is not a valid child of xsl:stylesheet, so I can't do at
top level

<xsl:choose>
<xsl:when test="$lang='en-GB'">
<xsl:include href='i18n-en-GB-include.xslt'/>
</xsl:when>
</xsl:choose>

I'm running out of ideas. If anyone has successful recipes for
conditional include in XSL I'd love to hear them.
Jun 27 '08 #1
3 3599
* Simon Brooke wrote in comp.text.xml:
>I'm trying to do internationalis ation by using xsl:include to include
a different file depending on the locale setting, and I'm completely
failing.

I've tried several different approaches:

<xsl:include href="concat( 'i18n-', $locale, '-include.xslt)"/>
You would have to use { ... } for an attribute value template, but in
XSLT 1.0 the href attribute does not take an attribute value template.
> <xsl:include>
<xsl:attribut e name="href">
<xsl:value-of select="concat( 'i18n-', $locale, '-include.xslt)"/>
</xsl:attribute>
</xsl:include>
The xsl:attribute element applies only to result elements, I think.
> <xsl:include href="$i18n-include"/>
See above.
>xsl:choose is not a valid child of xsl:stylesheet, so I can't do at
top level

<xsl:choose>
<xsl:when test="$lang='en-GB'">
<xsl:include href='i18n-en-GB-include.xslt'/>
</xsl:when>
</xsl:choose>
Indeed.

What you want to do is not supported by XSLT 1.0. It might be wise to
separate the transformation code and the localized text, then you could
use e.g. the document() function to include the localized text.
--
Björn Höhrmann · mailto:bj****@h oehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 27 '08 #2
In article <5e************ *************** *******@i76g200 0hsf.googlegrou ps.com>,
Simon Brooke <st******@googl email.comwrote:
>I'm trying to do internationalis ation by using xsl:include to include
a different file depending on the locale setting, and I'm completely
failing.

I've tried several different approaches:
<xsl:include href="concat( 'i18n-', $locale, '-include.xslt)"/>
As Bjoern says, you can't do that. <xsl:includei s a compile-time
inclusion, like #include in C. XSLT 1.0 doesn't have any dynamic
features of that kind, though EXSLT has a dyn:evaluate function
for (effectively) compiling an XPath at run-time.

Can you parametrise your internationalis ation so that you dynamically
select data rather than code?

-- Richard
--
In the selection of the two characters immediately succeeding the numeral 9,
consideration shall be given to their replacement by the graphics 10 and 11 to
facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
Jun 27 '08 #3
On May 26, 3:53*pm, rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
In article <5ec7e828-f05a-4d79-b061-fcd1c73da...@i7 6g2000hsf.googl egroups.com>,
Simon Brooke *<still...@goog lemail.comwrote :
I'm trying to do internationalis ation by using xsl:include to include
a different file depending on the locale setting, and I'm completely
failing.
I've tried several different approaches:
* *<xsl:include href="concat( 'i18n-', $locale, '-include.xslt)"/>

As Bjoern says, you can't do that. *<xsl:includei s a compile-time
inclusion, like #include in C. *XSLT 1.0 doesn't have any dynamic
features of that kind, though EXSLT has a dyn:evaluate function
for (effectively) compiling an XPath at run-time.

Can you parametrise your internationalis ation so that you dynamically
select data rather than code?
[Hi Richard, long time no see]

Thanks to you both.

The problem with i18n is not the languages and cultures with which we
are familiar, but extension to languages and cultures with which we
are not. In particular, with making a framework which has enough
flexibility to extend to languages and cultures with which we are not.
For example, the indefinite article:

<xsl:template name="i18n-indefinite-article">
<!-- a string, presumed to be a noun- e.g. the name of a domain
entity -->
<xsl:param name="noun"/>
<xsl:variable name="initial" select="substri ng( $noun, 1, 1)"/>
<xsl:choose>
<xsl:when test="$initial = 'A' or $initial = 'a'">
<xsl:value-of select="concat( 'an ', $noun)"/>
</xsl:when>
<xsl:when test="$initial = 'E' or $initial = 'e'">
<xsl:value-of select="concat( 'an ', $noun)"/>
</xsl:when>
<xsl:when test="$initial = 'I' or $initial = 'i'">
<xsl:value-of select="concat( 'an ', $noun)"/>
</xsl:when>
<xsl:when test="$initial = 'O' or $initial = 'o'">
<xsl:value-of select="concat( 'an ', $noun)"/>
</xsl:when>
<xsl:when test="$initial = 'U' or $initial = 'u'">
<xsl:value-of select="concat( 'an ', $noun)"/>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="concat( 'a ', $noun)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

In English, the indefinite article prefixes the noun to which it
applies; in many Scandinavian languages is postfixes the noun; and in
most Slavonic languages it is missing altogether. English also
demonstrates special cases - the indefinite article used depends on
whether the noun has an initial vowel. Or again, consider plurals:

<xsl:template name="i18n-plural">
<!-- a string, presumed to be a noun -->
<xsl:param name="noun"/>
<xsl:choose>
<xsl:when test="$noun='Pe rson'">People</xsl:when>
<!-- add other special cases here -->
<xsl:when test="starts-with( substring($noun , string-
length($noun) ), 's')">
<xsl:value-of select="concat( $noun, 'es')"/>
</xsl:when>
<xsl:when test="starts-with( substring($noun , string-
length($noun) ), 'y')">
<xsl:value-of select="concat( substring( $noun, string-
length($noun)), 'ies')"/>
</xsl:when>
<xsl:otherwis e>
<xsl:value-of select="concat( $noun, 's')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

In British English - and, I'm sure, in many other languages - this is
a mess of special cases.

If internationalis ation were simply a matter of a lookup table which
returned fixed boilerplate strings, then the document() solution would
work. And if anyone could suggest a (reasonably efficient) way in
which things like indefinite article rules could be encoded as pure
data then that would interest me greatly. But I think that to do the
things I need to do I need the flexibility of having code - so that
people coming after me who write the internationalis ation code for
other locales with which I'm completely unfamiliar have enough
richness to do what they need to do.

The alternate solution I can see is to do a two-phase transformation,
where the first transformation builds an xslt stylesheet with the
correct internationalis ation data in it and the second transformation
builds the end-user document... which I can do, since this is a
transformation which gets run at build time not at run time, so
performance is not critical. I'm sort of glad I hadn't missed
anything, but I'm sorry there isn't a more elegant solution.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2304
by: N. Demos | last post by:
I'm having problems with a custom JS object (XMLLoadObject) I designed to load XML and XSL files, perform an XSL transform with them and embed the resultant HTML fragment into the host HTML document. I designed this object so that I could generate and embed HTML fragments from more than one XML/XSL source into a single HTML document. This is done by instantiating an XMLLoadObject with an XML filename, an XSL filename, and the ID of the...
2
3228
by: Keith Chadwick | last post by:
I have been running some tests with regards to xsl:include and xsl:import with the same results on both and I am wondering if someone can explain this behavior to me! First off the xslt file is being loaded as in dim myXSLT as new XslTransform() myXSLT.load("scripts/clnt.home.body.xslt") The load craps out when I change the xsl:include, tried all of the following
1
1688
by: Keith Chadwick | last post by:
Have been doing a fair amount of reading but at this point no joy. The scenario is - XSL template is stored within db. - Template has a xsl:include statement as <xsl:include href="inc.template.methods.xsl"/> I now I have to pass a resolver when I use the load method so that it understands the xsl include as in:
6
2926
by: Gideon de Swardt | last post by:
I am trying to do a server side transformation using an xsl:include in my xslt stylesheet. The include stylesheet is stored /Library/abo.Library.xslt and is included in multiple xslts, one example would be /Valuation/ValuationSelect.xslt which is also used on the client side via JavaScript and MSXML2.FreeThreadedDOMDocument.4.0. Client side the include and transformation without any problems but it is when I am trying to do the...
0
1189
by: Eugene Banks | last post by:
I am running into a permissions issue when trying to load an XSLT document. The XSLT document has an xsl:include element that references a local url: <xsl:include href="http://localhost/file/path/here/Common.xslt" /> When I attempt to load the XSLT file into an XslTransform, an exception is thrown:
1
1684
by: lele1979 | last post by:
Hi XSL Community, I would do a file in PDF with FO and XSL/XML tecnology. In a precisely moment of a creation of this PDF file I must call a precisely template from a precisely XSL file, that I have already included. The name of this template is the same that from a file XML.
0
1848
by: jephperro | last post by:
Hi, I'm trying to do something with multiple xml files and am wondering if it is possible. I have 2 XML feeds: One is a list of locations, LOC.XML One is a list of products,PROD.XML I have 2 separate XSL files.
2
1450
by: sandra55 | last post by:
Hi, I need to include different stylesheets in my stylesheet so that I can use their stylesheet. However, as soon as I have my stylesheets in different files, it does not work anymore. But they do work when they are implemented in the same file. So I think there is something wrong with the way I include the files or call them. This is how i do it: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"...
3
2665
markmcgookin
by: markmcgookin | last post by:
Hi, I know this is a common issue, but to be honest all the sites I find with solutions to this dont explain it well at all. I have a variable ($fileName) which I want to add to http://tempuri.org/ then attach .xsd to the end
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.