xsl-list
[Top] [All Lists]

[xsl] Re: Identity Transform with special grouping

2011-02-05 08:12:28
"sections" element is not showing up in my output. I do not know , how
could I include that in my xslt.

Thanks,
Sen

On Friday, February 4, 2011, Senthilukvelaan
<skumaravelan(_at_)googlemail(_dot_)com> wrote:
Hi

I am trying to do the identity transform with grouping on the node
name under section. I want select only the first section node and put
it under sections. Based the conditions I might need to select more
than one section. The application might change the configuration to
make 2 or 3 ..n.


My XML looks like
<event>
<note>
</note>
<note>
</note>
<header>
<section>
<para1>test</para1>
<para1>test</para1>
</section>
<section>
<para1>test</para1>
<para1>test</para1>
</section>
<section>
<para1>test</para1>
<para1>test</para1>
</section>
</header>
<payload>
<elements/>
</payload>
</event>

My xslt looks for the expected out


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"  indent="yes"
encoding="UTF-8" />

<!--NO change here is expected, because node names are dynamic in nature-->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node()| @*"/>
</xsl:copy>
</xsl:template>

 <xsl:template match="header/section[position() &lt; 2]" >
     <xsl:apply-templates select="@*|node()"/>
</xsl:template>

<xsl:template match="section" >
</xsl:template>
</xsl:stylesheet>

My expected output is
<event>
<note>
</note>
<note>
</note>
<header>
<sections>
<section>
<para1>test</para1>
<para1>test</para1>
</section>
</sections>
</header>
<payload>
<elements/>
</payload>
</event>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>