[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

another placement of nodes question

Subject: another placement of nodes question
From: a kusa <akusa8@xxxxxxxxx>
Date: Mon, 25 Jan 2010 08:53:23 -0600
 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::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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.