This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Recursively link XML blocks




Costantino_Sertorio@amsinc.com wrote:
> 
> Hello everybody,
> I am trying (without success, at the moment...) to do the following:
> 
> XML document:
> ...
> <element_A>
>      textA textA textA
>      <insert>element_B</insert>
>      textA textA textA
> </element_A>
> 
> <element_B>
>      textB textB textB
>      <insert>element_C</insert>
>      textB textB textB
> </element_B>
> 
> <element_C>
>      textC textC textC
>      textC textC textC
> </element_C>
> ....etc.
> 
> Desired output:
>      textA textA textA
>      textB textB textB
>      textC textC textC
>      textC textC textC
>      textB textB textB
>      textA textA textA
> 

Hello,
try this :
<?xml version="1.0"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
    version="1.0">

    <xsl:output  method='text'  encoding='ISO-8859-1' />
    
    
    <xsl:template match="/">
        <xsl:call-template name="make_insert">
        	<xsl:with-param name="elem" select="'element_A'" />
        </xsl:call-template>
    </xsl:template>
    
    
    <xsl:template match="insert">
        <xsl:call-template name="make_insert">
        	<xsl:with-param name="elem" select="." />
        </xsl:call-template>
    </xsl:template>
    
    
    <xsl:template name="make_insert">
    	<xsl:param name="elem"/>
    	<xsl:for-each select="//*[name() = $elem ]" >
    		<xsl:value-of select="./child::text()[1]"/>
    		<xsl:apply-templates/>
    		<xsl:value-of select="./child::text()[2]"/>
    	</xsl:for-each>
    </xsl:template>
    
    
    
    <xsl:template match="text()"/>
    
</xsl:stylesheet>

Philippe Drix
www.objectiva.fr

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]