[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] preceding-sibling::node() apply template -xsl:copy


Subject: Re: [xsl] preceding-sibling::node() apply template -xsl:copy
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 16 Apr 2012 22:05:46 -0400

At 2012-04-16 18:49 -0700, Senthilukvelaan wrote:
Hi All,
I am using a xslt identity transform and I have one more template to
manipulate "EVENTHEADER" header.
I am not sure ,how to do exclude the  " xmlns:ns2="uri" attribute in
the output using the preceding-sibling::node() apply template.

<ns2:local xmlns:ns2="uri"><EVENTHEADER>


<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>



  <xsl:template match="EVENTHEADER[EVENT_TYPE]">
<xsl:copy>

Using <xsl:copy> copies the element plus all attached namespace nodes, so what you need to do is reconstitute the element instead of copy it.


Use <xsl:element name="{name(.)}"> instead since your element is not in a namespace itself.

You would use <xsl:element name="{local-name(.)}"> if you needed to strip a prefix from the element.

But ... remember that *all* of your elements in your source tree will have the namespace node for ns2: attached, so you will have to reconstitute *all* your elements that you need from the source tree. Copying any of them will copy the attached namespace node.

So, an identity transformation that ignores attached namespace nodes would look like:

 <xsl:template match="@*|text()|comment()|processing-instruction()">
    <xsl:copy/>
 </xsl:template>

 <xsl:template match="*">
    <xsl:element name="{name(.)}">
       <xsl:apply-templates select="@*|node()"/>
     </xsl:element>
 </xsl:template>

<xsl:apply-templates select="EVENT_TYPE[position() &lt;
2]/preceding-sibling::node()" />
< EVENT_TYPES>
<xsl:apply-templates select="EVENT_TYPE[position() &lt; 2]" />
</EVENT_TYPES>
<xsl:apply-templates select="EVENT_TYPE[last()]/following-sibling::node()" />
</xsl:copy>
</xsl:template>


Input: <ns2:local xmlns:ns2="uri"><EVENTHEADER>

Actual output:
<EVENTHEADER  xmlns:ns2="uri">

Expected output:
 <EVENTHEADER>
</EVENTHEADER >

Any pointer would be really helpful.

I hope this helps.


. . . . . . . Ken

--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- May 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


Current Thread
Keywords