Subject: Re: [xsl] ENCODING COUNTRY CODES From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx> Date: Mon, 25 Apr 2005 03:59:20 -0700 (PDT) |
Please try this XSL.. It is a modified identity stylesheet.. In this stylesheet, I have made some assumtions - 1) The CountryCode.xml file you posted specifies England. So I think source.xml should also specify England (not ENGLAND) . I tested by changing to England.. 2) My stylesheet is replacing a "string pattern" (its first occurence) in <affiliation> tag with value from CountryCode.xml file.. This is having following effect.. <affiliation> <country code="in">India</country>n Institute of Technology, Chennai, India - 610545 </affiliation> Hope you may take the idea from this stylesheet.. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:variable name="country" select="document('CountryCode.xml')" /> <xsl:template match="node() | @*"> <xsl:copy> <xsl:apply-templates select="node() | @*" /> </xsl:copy> </xsl:template> <xsl:template match="para" /> <xsl:template match="text()[not(normalize-space() = '')]"> <xsl:variable name="temp" select="." /> <xsl:for-each select="$country/allcountry/country[contains($temp, .)]"> <xsl:value-of select="substring-before($temp, .)" /> <country code="{@code}"> <xsl:value-of select="." /> </country> <xsl:value-of select="substring-after($temp, .)" /> </xsl:for-each> </xsl:template> </xsl:stylesheet> Regards, Mukul --- Arulxml@xxxxxxxxxxxx wrote: > Dear all, > > Greetings > > I require XSLT support in amending the country codes > to my resulting XML. I have all country names with > relevant country codes in an external XML file > (i.e., CountryCode.xml, given below), here I require > all countries needs to be encoded in my each > <affiliation> of the source xml, also please find > below the resulting xml for your easy understanding. > > CountryCode.xml > <allcountry> > <country code="gb">England</country> > <country code="in">India</country> > <country code="us">USA</country> > <allcountry> > > source.xml > <root> > <para>Some text</para> > <affiliation>Indian Institute of Technology, > Chennai, India - 610545</affiliation> > <affiliation>SOME INSTITUTION NAME, ENGLAND - > 12245</affiliation> > <affiliation>IEEE Institution, NY, > USA</affiliation> > </root> > > result.xml > <root> > <affiliation>Indian Institute of Technology, > Chennai, <country code="in">India</country> - > 610545</affiliation> > <affiliation>SOME INSTITUTION NAME, <country > code="gb">ENGLAND</country> - 12245</affiliation> > <affiliation>IEEE Institution, NY, <country > code="us">USA</country></affiliation> > </root> > > Please advise me how the XSLT should look, many > thanks in advance. > > Best regards > Arul Kumar > > > __________________________________________________________________ > Switch to Netscape Internet Service. > As low as $9.95 a month -- Sign up today at > http://isp.netscape.com/register > > Netscape. Just the Net You Need. > > New! Netscape Toolbar for Internet Explorer > Search from anywhere on the Web and block those > annoying pop-ups. > Download now at > http://channels.netscape.com/ns/search/install.jsp > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] ENCODING COUNTRY CODES, Arulxml | Thread | [xsl] XSL-FO - Repeating Tables &, craig webber |
[xsl] ENCODING COUNTRY CODES, Arulxml | Date | [xsl] XSL-FO - Repeating Tables &, craig webber |
Month |