Subject: Re: [xsl] using xsl to substitute synonyms or translate From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Tue, 07 Jan 2003 16:33:35 -0500 |
<my:nflmap xmlns:my="http://my.namespace"> <!-- this element, in a non-xsl namespace, will serve you as a kind of lookup table for your teams --> <team name="49ers" city="San Francisco"/> <team name="Cowboys" city="Dallas"/> <!-- etc. etc. for all teams --> </my:nflmap>
<xsl:variable name="nflmap" select="document('')/*/my:nflmap"/> <!-- this variable saves having to find and load the table every time we want it, which would be expensive -->
<xsl:key name="teamsbyname" match="team" use="@name"/> <!-- sets up a key so we can retrieve team nodes by name -->
<xsl:template match="nflTeamNames"> <nflCities> <xsl:apply-templates/> </nflCities> </xsl:templates>
<xsl:template match="name"> <xsl:variable name="thisname" select="."/> <!-- binds our context node to a variable so we can get to it below --> <xsl:for-each select="$teamsbyname"> <!-- the for-each changes our context node, which we need to do so we can use our key --> <city> <xsl:value-of select="key('teamsbyname',$thisname)/@city"/> <!-- reports the string value of the @city attribute on the 'team' (lookup) element node retrieved by the key --> </city> </xsl:for-each> </xsl:template>
Cheers, Wendell
I have a problem that I think is similar to translating words in one language to words in another language and I was wondering if I could use xsl to do it.
I know what my source input will be (example below) and I know what I want to output to be, but I can't fathom how to build an xsl to get the output.
I thought I could use the translate function, but there would be a long list of things to translate. There are 32 teams and I want to use this process again (on something unrelated) for a list of over 300 items.
Here is what my source document will look like
<nflTeamNames> <name>49ers</name> <name>Cowboys</name> . . . <name>Seahawks</name> <nflTeamNames>
Here is what I want the output to look like:
<nflCities> <city>San Francisco</city> <city>Dallas</city> . . . <city>Seattle</city> </nflCities>
In case you don't know American football the 49ers are the San Francisco team, the Cowboys are the Dallas team and so on. :-)
Regards,
Tom
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] using xsl to substitute synon, Thomas McDonald | Thread | Re: [xsl] using xsl to substitute s, Thomas McDonald |
[xsl] writing xsl for processing do, Hubert Holtz | Date | Re: [xsl] using xsl to substitute s, Wendell Piez |
Month |