Re: [xsl] grabbing chunks of preceding-siblings between tables

Subject: Re: [xsl] grabbing chunks of preceding-siblings between tables
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Thu, 4 Oct 2007 23:11:14 +0530
Here is another XSLT 1.0 solution:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

 <xsl:output method="xml" indent="yes" />

 <xsl:template match="root">
   <root>
     <xsl:for-each select="table">
       <xsl:variable name="x" select="generate-id()" />
       <table>
         <xsl:copy-of
select="preceding-sibling::*[generate-id(following-sibling::table[1])
= $x][not(self::table)]" />
         <xsl:copy-of select="*" />
       </table>
     </xsl:for-each>
   </root>
 </xsl:template>

</xsl:stylesheet>

On 10/4/07, Spencer Tickner <spencertickner@xxxxxxxxx> wrote:
> Hi List,
>
> Thanks in advance for the help. I'm doing some pre-processing of a XML
> Dump of tables. I'm trying to associate header information in the
> table to the table itself. I'm having difficulty figuring out how to
> do this.. Anyway, examples always seem to say it better (XSLT 2.0 is
> fine):
>
> XML
>
> <?xml version="1.0"?>
> <root>
>        <title1>Title for Table 1</title1>
>        <title2>sub-title for Table 1</title2>
>        <caption>Caption for Table 1</caption>
>        <para_norm>Any number of different paragraphs that belong with Table
> 1</para_norm>
>        <table>
>                <cell>Foo</cell>
>                <cell>Bar</cell>
>        </table>
>        <title2>Table 2 only has subtitle</title2>
>        <caption>Caption for Table 2</caption>
>        <para_diff>Any number of different paragraphs that belong with Table
> 2</para_diff>
>        <table>
>                <cell>Foo</cell>
>                <cell>Bar</cell>
>        </table>
>        <title1>Title for Table 3</title1>
>        <title2>sub-title for Table 3</title2>
>        <caption>Caption for Table 3</caption>
>        <para_norm>Any number of different paragraphs that belong with Table
> 3</para_norm>
>        <table>
>                <cell>Foo</cell>
>                <cell>Bar</cell>
>        </table>
> </root>
>
> Desired XML Output:
>
> <?xml version="1.0"?>
> <root>
>        <table>
>                <title1>Title for Table 1</title1>
>                <title2>sub-title for Table 1</title2>
>                <caption>Caption for Table 1</caption>
>                <para_norm>Any number of different paragraphs that belong with Table
> 1</para_norm>
>                <cell>Foo</cell>
>                <cell>Bar</cell>
>        </table>
>        <table>
>                <title2>Table 2 only has subtitle</title2>
>                <caption>Caption for Table 2</caption>
>                <para_diff>Any number of different paragraphs that belong with Table
> 2</para_diff>
>                <cell>Foo</cell>
>                <cell>Bar</cell>
>        </table>
>        <table>
>                <title1>Title for Table 3</title1>
>                <title2>sub-title for Table 3</title2>
>                <caption>Caption for Table 3</caption>
>                <para_norm>Any number of different paragraphs that belong with Table
> 3</para_norm>
>                <cell>Foo</cell>
>                <cell>Bar</cell>
>        </table>
> </root>
>
> I've tried a number of different things, but can't seem to translate
> "Take all elements between <table> and add as child to following
> <table>" into XSLT. Any help would be greatly appreciated.
>
> Thanks,
>
> Spencer


-- 
Regards,
Mukul Gandhi

Current Thread