Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Help with XSLT please [Thread Next] Re: Help with XSLT pleaseTo: NULL Date: 6/8/2008 1:00:00 PM
KP wrote:
> The following XML fragment is a simplification of a problem I'm trying
> to solve.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <document>
> <index><![CDATA[<div class="index">]]>
> <partref/><![CDATA[</div>]]>
> <partref/>
> </index>
> <part>
> Part1
> </part>
> <part>
> Part2
> </part>
> </document>
>
> I want to render this as
>
> <div class="index>Part1Part2</div>
Are you sure the 'Part2' belongs inside of the div element? Because
above the second 'partref' is outside of the (escaped) div.
It is also not clear where the 'div class="index"' comes from, whether
it comes from the 'index' element or from the escaped 'div' element.
Assuming you want to transform the 'index' element into a 'div
class="index"' element then you can use
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/document">
<xsl:apply-templates select="index"/>
</xsl:template>
<xsl:template match="index">
<div class="index">
<xsl:apply-templates select="*"/>
</div>
</xsl:template>
<xsl:template match="index/partref">
<xsl:apply-templates
select="../../part[count(current()/preceding-sibling::partref) + 1]"/>
</xsl:template>
<xsl:template match="part">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
</xsl:stylesheet>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
