Jump to content

Generate new XML without some nodes


sgubert

Recommended Posts

Hi,I have a problem that I am not finding a solutionI need create a XSL that generate a new xml file without some nodes.I have a research on xsl:copy and xsl:copy-of, but i could not make it works.Example node:

<Listing>	<Ambients>		<Categories>			<Category description="Kitchen">				<Items>					<ITEM description="item1" quantity="2" unit="m2" width="400" height="700" depth="350">						<REFERENCES>							<MODEL REFERENCE="ABC"/>							<CODE REFERENCE="100"/>							<HOLE REFERENCE="Y"/>							<COMPLETE REFERENCE="ABC.100.43"/>						</REFERENCES>											</ITEM>					// more ITEMS				</Items>			</Category>			//more CATEGORIES		</Categories>	</Ambients></Listing>

I need create a new xml file, identical to the original, but without the node ITEM that ITEM/REFERENCES/MODEL/@REFERENCE == ABCI hope I have been clear.Can someone help me??Thanks,Samuel

Link to comment
Share on other sites

With XSLT 2.0:

<xsl:param name="mr" select="'ABC'"/><xsl:template match="@* | node()">  <xsl:copy>	<xsl:apply-templates select="@*, node()"/>  </xsl:copy></xsl:template><xsl:template match="ITEM[REFERENCES/MODEL/@REFERENCE = $mr]"/>

With XSLT 1.0 you are not allowed to use variable or parameter reference in a match pattern so you need e.g.

<xsl:param name="mr" select="'ABC'"/><xsl:template match="@* | node()">  <xsl:copy>	<xsl:apply-templates select="@* | node()"/>  </xsl:copy></xsl:template><xsl:template match="ITEM">  <xsl:if test="not(REFERENCES/MODEL/@REFERENCE = $mr])">	<xsl:copy>	  <xsl:apply-templates select="@* | node()"/>	</xsl:copy>  </xsl:if></xsl:template>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...