Tuesday, November 20, 2007

Partially copying XML using XSL

Subject: Sample xls that copies entire XML source tree, but skips an element as specified in the xls.

Note: the indentation is messed up due to the xml characters used.

The source xml file includes a link to the xsl for display purposes (xml and xls as stored in the same folder):

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="display.xsl"?>

<data>
<employee id="100">
<lastname fooAttr="123">Basta</lastname>
<insertion>van</insertion>
<firstname>Marco</firstname>
</employee>

<employee id="102">
<lastname fooAttr="123">Kruif</lastname>
<insertion></insertion>
<firstname>Jan</firstname>
</employee>

</data>


The xsl file (called display.xsl), the employee entry with firstname 'Marco' is skipped:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*">
<xsl:copy> <xsl:apply-templates/> </xsl:copy>
</xsl:template>

<xsl:template match="/data/employee[firstname='Marco']"/>

</xsl:stylesheet>

No comments: