Subject: [xsl] another placement of nodes question From: a kusa <akusa8@xxxxxxxxx> Date: Mon, 25 Jan 2010 08:53:23 -0600 |
Hi I have a scenario as shown below in my xml: Source XML: <root> <level1> <st1> <desc><text>sample desc</text></desc> <!-- A <spec> element can occur here as well--> <level2> <item><text>r1 </text></item> <item><text>r2</text></item> </level2> <spec><para>Some spec 1</para></spec> <spec><para>Some spec 2</para></spec> </st1> </level1> </root> Here is my desired output XML: <root> <step1> <text>sample desc</text> <step2> <text>r1</text> </step2> <step2> <text>r2</text> <spec><para>Some spec 1</para></spec> <spec><para>Some spec 2</para></spec> </step2> </step1> </root> Please note that every item under level2 becomes a step2 in my output XML. Here is my XSL for level2: <xsl:template match="level2"> <xsl:for-each-group select="./item" group-by="."> <text><xsl:apply-templates/></text> <xs:apply-templates select="../parent::st1/child::spec[not(preceding-sibling::*[1][self::desc])] </xsl:for-each-group> </xsl:template> The reason I write the condition "not(preceding-sibling::*[1][self::desc])]" is because there is a possiblity that there is a <spec> element after <desc> in the source XML. I do not want to match that element. Now here is my problem. With this template, my output looks like this: <root> <step1> <text>sample desc</text> <step2> <text>r1</text> <spec><para>Some spec 1</para></spec> <spec><para>Some spec 2</para></spec> </step2> <step2> <text>r2</text> <spec><para>Some spec 1</para></spec> <spec><para>Some spec 2</para></spec> </step2> </step1> </root> So instead of <spec> repeating only under the second <item>, it repeats under both. How do I make <spec> go under only the second item? I have tried <xsl:for-each-group> but with no success. So maybe there is something that I am not understanding in this grouping technique. Can the experts please help me on this? Thanks in advance for all your help.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: Is there a forum frontend, Vladimir Nesterovsky | Thread | RE: [xsl] another placement of node, Robby Pelssers |
[xsl] Is there a forum frontend mir, Ben Stover | Date | RE: [xsl] another placement of node, Robby Pelssers |
Month |