[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] another placement of nodes question
Subject: RE: [xsl] another placement of nodes question From: "Robby Pelssers" <robby.pelssers@xxxxxxxxx> Date: Mon, 25 Jan 2010 16:36:46 +0100 |
Hi, It's not clear to me what should happened if a <spec> element occurs after the <desc> on level1. But I don't think you need to group here... Why not just iterate over all level level2/item and check when position() = last() and then output the <spec>? Robby Pelssers -----Original Message----- From: a kusa [mailto:akusa8@xxxxxxxxx] Sent: Monday, January 25, 2010 3:53 PM To: xsl-list Subject: [xsl] another placement of nodes question 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::des c])] </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] another placement of nodes qu, a kusa | Thread | Re: [xsl] another placement of node, Martin Honnen |
[xsl] another placement of nodes qu, a kusa | Date | [xsl] Setting Namespace on Generate, Roger L. Cauvin |
Month |
Keywords