An XSLT copy of how I can skip a node child when copying through XSL: copy

Question for copy input:

<Rel> <IRel UID1="3a4d1d2909d0" UID2="35fe61082294" DefUID="AssetSupplier" /> <IObject UID="3a4d1d2909d0.AssetSupplier.35fe61082294" /> <SPXSupplier> <ISPFOrganization /> <ISPFAdminItem /> <IObject UID="b73ebb87-cd36-4c25-b9ed-35fe61082294" Description="local supplier made in form (10C)" Name="CASTROL1200" /> <ISupplierOrganization /> </SPXSupplier> </Rel> 

Conclusion: I just want to skip SPXSupplier and its child node in my release

 <Rel> <IRel UID1="3a4d1d2909d0" UID2="35fe61082294" DefUID="AssetSupplier" /> <IObject UID="3a4d1d2909d0.AssetSupplier.35fe61082294" /> </Rel> 

I am currently using this copy, which copies all things, including the child, <xsl:copy-of select="self::node()"/>

I need the tags <Rel> , <IRel> and <IObject> . excluding other things.

+4
source share
2 answers

xsl:copy-of copies the entire subarea. To exclude an SPXSupplier element, you can use the following approach:

 <xsl:template match="//Rel"> <xsl:copy> <xsl:apply-templates select="@*|IRel|IObject"/> </xsl:copy> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> 
+2
source

Here is a clarification of Alex's answer.

 <xsl:template match="SPXSupplier"/> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> 

An empty template for SPXSupplier means that if one of these elements falls into a subtree under this element, it is not processed. I also used a version of the identity template that correctly copies attributes, which is more efficient.

+6
source

Source: https://habr.com/ru/post/1339330/