Subject: RE: [xsl] How to select elements based on the value(s) of a multi-valued attribute? From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Mon, 28 Jan 2002 16:42:55 -0000 |
This is a good use case for the XSLT 2.0 support for sequence-valued attributes! I suggest that for future transition to XML Schema you use a space-separated list rather than comma-separated. Then (for XSLT 1.0) I suggest you use select="translation[ contains( concat(' ', @language, ' '), concat(' ', $language, ' ') )]" Mike Kay > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Rogier > Hofboer > Sent: 28 January 2002 16:05 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] How to select elements based on the value(s) of a > multi-valued attribute? > > > Hi everybody, > > Can somebody help me to solve the following problem? > A resource can be translated into more languages > (and multiple times in the same language) and every > translation in that language is applicable for one or > more countries. This is because if one language is > spoken in more countries, some resources are translated > once i.e. the translations for the word "Name" but the > text on the homepage is translated more times in the same > language but each translation is appropiate for another country. > > > xml: > > <resource name="hello"> > <translation> > <language>fr</language> > <country>be</country> > <country>fr</country> > <!-- translation in french for france and belgium --> > <text>Bonjour</text> > </translation> > <translation> > <language>nl</language> > <country>be</country> > <!-- translation in dutch for belgium --> > <text>Goedendag</text> > </translation> > <translation> > <language>nl</language> > <country>nl</country> > <!-- translation in dutch for the netherlands --> > <text>Hallo</text> > </translation> > <translation> > <language>en</language> > <country>nl</country> > <country>be</country> > <!-- translation in english for the netherlands and belgium --> > <text>Hello</text> > </translation> > <translation> > <language>en</language> > <country>fr</country> > <!-- translation in english for france --> > <text>Bon Hello (just an example)</text> > </translation> > </resource> > > xslt: > > <?xml version="1.0"?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="html" indent="yes"/> > <xsl:param name="country" select="'nl'" /> > <xsl:param name="language" select="'nl'" /> > <xsl:template match="//resource"> > <xsl:apply-templates select="translation[language=$language and > country=$country]"/> > </xsl:template> > <xsl:template match="//translation"> > <xsl:apply-templates select="text"/> > </xsl:template> > </xsl:stylesheet> > > This works :-) Changing the 2 parameters also works :-) > (they are in the future passed to the stylesheet processor, > already tested > with MSXML and it worked, > now it are just defaults if nothing is passed) > > BUT I don't like the XML syntax... > > I want this XML as input and I need an XSLT with the same > result as above: > (not that this is also possible: country="be,fr,en,de" and > even in some > cases > language="nl,fr,en" or something like that, I would like it > if country="be, > nl, fr" > would be possible...) > > xml: > > <resource name="hello"> > <translation language="fr" country="be,fr">Bonjour</translation> > <translation language="nl" country="be">Goedendag</translation> > <translation language="nl" country="nl">Hallo</translation> > <translation language="en" country="nl, be">Hello</translation> > <translation language="en" country="fr">Bon Hello (just an > example)</translation> > </resource> > > xslt: > > ???? > > Can anybody help me out? > > Thanks in advance, > > Rogier Hofboer > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to select elements based , Rogier Hofboer | Thread | Re: Re: [xsl] How to select element, Rogier Hofboer |
RE: [xsl]: Context inside nested fo, Michael Kay | Date | Re: [xsl] how to format page number, G. Ken Holman |
Month |