Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - How to select particular items from repeating 'generic' attributes? >Thread Next - Re: How to select particular items from repeating 'generic' attributes? Re: How to select particular items from repeating 'generic' attributes?To: NULL Date: 2/6/2006 10:35:00 PM 42 wrote:
> Hi,
> I'm pretty new to XSL, and I've bumped into what is probably (hopefully)
> a simple problem.
>
> I need to convert a simple xml document containing just repeated
> 'generic' data blocks of:
>
> <record>
> <data>Bob</data>
> <data>Smith</data>
> ...
> </record>
>
> to:
>
> <person>
> <firstname>Bob</firstname>
> <lastname>Smith</lastname>
> ...
> </person>
>
> The source xml contains the same number of <data> elements for each
> record, are in a consistent order, with no omissions.
>
> I've figured out how to use foreach to iterate over the person records,
Don't. Use templates instead, it's faster and clearer.
<xsl:template match="record">
<person>
<xsl:apply-templates/>
</person>
</xsl:template>
<xsl:template match="data[1]">
<firstname>
<xsl:apply-templates/>
</firstname>
</xsl:template>
<xsl:template match="data[2]">
<surname>
<xsl:apply-templates/>
</surname>
</xsl:template>
Keep for-each for things like sorting and accessing nodes out of
document order.
> but can't see how to select the nth occurence of <data> within each
> record.
Think like a tree, not like a chainsaw :-)
///Peter
--
XML FAQ: http://xml.silmaril.ie/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
