Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help with XSLT please

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent