Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - xslt concatenation [Thread Next] Re: xslt concatenationTo: NULL Date: 1/14/2009 8:00:00 PM Here is a stylesheet for this,
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
version=3D"1.0">
<xsl:output method=3D"xml" indent=3D"yes" />
<xsl:template match=3D"node() | @*">
<xsl:copy>
<xsl:apply-templates select=3D"node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match=3D"civic-address">
<xsl:copy>
<xsl:apply-templates />
<xsl:if test=3D"HNO | HNS | PRD | A6 | POD | STS">
<street><xsl:value-of select=3D"normalize-space(concat(HNO, ' ',
HNS, ' ', PRD, ' ', A6, ' ', POD, ' ', STS))" /></street>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template match=3D"HNO | HNS | PRD | A6 | POD | STS" />
</xsl:stylesheet>
This uses the modified identity transform pattern.
Regards,
Mukul
On Jan 15, 2:11=A0am, rouble <rou...@gmail.com> wrote:
> Hi All,
>
> I am just picking up xslt and I was wondering if I could get some
> pointers. I have an xml body that looks like this:
> =A0 =A0<location>
> =A0 =A0 =A0 =A0<civic-address>
> =A0 =A0 =A0 =A0 =A0 <country>US</country>
> =A0 =A0 =A0 =A0 =A0 <A1>New York</A1>
> =A0 =A0 =A0 =A0 =A0 <A2>King's County</A2>
> =A0 =A0 =A0 =A0 =A0 <A3>New York</A3>
> =A0 =A0 =A0 =A0 =A0 <A4>Manhattan</A4>
> =A0 =A0 =A0 =A0 =A0 <A5>Morningside Heights</A5>
> =A0 =A0 =A0 =A0 =A0 <A6>Broadway</A6>
> =A0 =A0 =A0 =A0 =A0 <PRD>N</PRD>
> =A0 =A0 =A0 =A0 =A0 <POD>SW</POD>
> =A0 =A0 =A0 =A0 =A0 <STS>Street</STS>
> =A0 =A0 =A0 =A0 =A0 <HNO>123</HNO>
> =A0 =A0 =A0 =A0 =A0 <HNS>A</HNS>
> =A0 =A0 =A0 =A0 =A0 <LMK>Low Library</LMK>
> =A0 =A0 =A0 =A0 =A0 <LOC>Room 543</LOC>
> =A0 =A0 =A0 =A0 =A0 <FLR>5</FLR>
> =A0 =A0 =A0 =A0 =A0 <NAM>Joe's Barbershop</NAM>
> =A0 =A0 =A0 =A0 =A0 <PC>10027-0401</PC>
> =A0 =A0 =A0 =A0</civic-address>
> =A0 =A0 </location>
> =A0 =A0<location>
> =A0 =A0 =A0 =A0<civic-address>
> =A0 =A0 =A0 =A0 =A0 =A0...
> =A0 =A0 =A0 =A0</civic-address>
> =A0 =A0 </location>
> =A0 =A0<location>
> =A0 =A0 =A0 =A0<civic-address>
> =A0 =A0 =A0 =A0 =A0 =A0...
> =A0 =A0 =A0 =A0</civic-address>
> =A0 =A0 </location>
>
> I need to translate this (using xslt) to create a new element called
> 'street' that has the values of HNO HNS PRD A6 POD STS from one civic-
> address. So the output should look like:
> =A0 =A0<location>
> =A0 =A0 =A0 =A0<civic-address>
> =A0 =A0 =A0 =A0 =A0 <country>US</country>
> =A0 =A0 =A0 =A0 =A0 <A1>New York</A1>
> =A0 =A0 =A0 =A0 =A0 <A2>King's County</A2>
> =A0 =A0 =A0 =A0 =A0 <A3>New York</A3>
> =A0 =A0 =A0 =A0 =A0 <A4>Manhattan</A4>
> =A0 =A0 =A0 =A0 =A0 <A5>Morningside Heights</A5>
> =A0 =A0 =A0 =A0 =A0 <street> 123 A N Broadway SW Street </street>
> =A0 =A0 =A0 =A0 =A0 <LMK>Low Library</LMK>
> =A0 =A0 =A0 =A0 =A0 <LOC>Room 543</LOC>
> =A0 =A0 =A0 =A0 =A0 <FLR>5</FLR>
> =A0 =A0 =A0 =A0 =A0 <NAM>Joe's Barbershop</NAM>
> =A0 =A0 =A0 =A0 =A0 <PC>10027-0401</PC>
> =A0 =A0 =A0 =A0</civic-address>
> =A0 =A0</location>
> =A0 =A0<location>
> =A0 =A0 =A0 =A0<civic-address>
> =A0 =A0 =A0 =A0 =A0 =A0...
> =A0 =A0 =A0 =A0</civic-address>
> =A0 =A0 </location>
> =A0 =A0<location>
> =A0 =A0 =A0 =A0<civic-address>
> =A0 =A0 =A0 =A0 =A0 =A0...
> =A0 =A0 =A0 =A0</civic-address>
> =A0 =A0 </location>
>
> If any of HNO HNS PRD A6 POD STS are missing, they should just be
> ignored. If all of them are missing, then a 'street' element should
> not be created.
>
> I am looking for tips on creating an efficient xslt for this.
>
> TIA,
> rouble
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
