[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: select lang attribute problem

Subject: Re: select lang attribute problem
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 28 Feb 2001 19:33:25 +0000
select lang
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
xsl'?

With your XML, you could use:

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

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>
         <xsl:copy-of select="@*" />
         <xsl:apply-templates mode="filter" />
      </xsl:copy>
   </xsl:if>
</xsl:template>

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:variable>
   <xsl:apply-templates select="saxon:node-set($filtered-copy)/*" />
</xsl:template>

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

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.