Senthilukvelaan wrote:
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()< 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>
Doesn't the stylesheet do what you want? I get the posted output, only
with additional indentation and white space but that is easily fixed by
adding
<xsl:strip-space elements="*"/>
in the stylesheet.
If you still have problems then please explain which XSLT processor you
use and which output you get.
Or are you simply asking how to parameterize the stylesheet? If you use
an XSLT 1.0 processor then you can't use a parameter or variable in a
match pattern but if you move to an XSLT 2.0 processor then you can use
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:param name="n" select="2"/>
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"
encoding="UTF-8" />
<xsl:strip-space elements="*"/>
<!--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="section"></xsl:template>
<xsl:template match="header/section[position() < $n]" >
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
</xsl:stylesheet>
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
--~------------------------------------------------------------------
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>
--~--