Re: [xsl] select lang attribute problem

Subject: Re: [xsl] select lang attribute problem
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 28 Feb 2001 19:33:25 +0000
Hi Jim,

> any ideas on selecting nodes based on the 2 following conditions being met
> a) existance of lang attribute is boolean false  ( in other words when 
> there is no explicit lang attribute select it as a default)
> if a) is TRUE then
> b) presence of lang="en" is boolean true ( the 'en' would be supplied by
> a xsl:param)

It sounds (and looks) as if you want to test each node to see whether:

  not(@xml:lang) or @xml:lang = $lang

[Note: this is roughly the same as:

  not(@xml:lang) or lang($lang)

 but doesn't inherit languages down the element hierarchy.]

> a solution at the top level of xsl would be most desirable with an
> xsl:param setting the desired language to extract ............ so
> far i've got lots of methods, just can't find anything elegant
> enough to apply to a larger system for multilingual support. any
> comments or pointers with how people are approaching multilingual
> xml/xsl..greatly appreciated.

I don't understand what you mean by 'solution at the top level of

With your XML, you could use:

<xsl:template match="test">
   <xsl:if test="not(@xml:lang) or @xml:lang = $lang">
      <xsl:value-of select="." />

If you're having to do this test all over the place then you might
want to consider a two-pass solution (either within the same
stylesheet or with separate ones) where you do one transformation to
filter in the languages you want, and another transformation to turn
that content into whatever output you're eventually after.

The first transformation can be as simple as the template:

<xsl:template match="*" mode="filter">
   <xsl:if test="not(@xml:lang) or @xml:lang = $lang">
         <xsl:copy-of select="@*" />
         <xsl:apply-templates mode="filter" />

If you wanted to just use one stylesheet, then you could manage the
entire thing with a central root-node-matching template:

<xsl:template match="/">
   <xsl:variable name="filtered-copy">
      <xsl:apply-templates mode="filter" />
   <xsl:apply-templates select="saxon:node-set($filtered-copy)/*" />

(Substitute saxon:node-set() for the node-set() function in your
particular processor.)

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread