Parent Branch Selection
Posted: Wed Nov 08, 2006 5:18 pm
Hello I have this problem.
My source XML is:
I want to filter by inactive files, but I want the same tree structure. I want this output:
I'm trying with XSLT like this:
But when I put the parent axe it selects all the node and I only want the direct parent, the branch.
My source XML is:
Code: Select all
<?xml version="1.0"?>
<root>
<folder name="pack1" other="unknownattributes">
<file name="file1" type="active"/>
<file name="file2" type="active"/>
<file name="file3" type="active"/>
<file name="file4" type="inactive"/>
<file name="file5" type="inactive"/>
</folder>
<folder name="pack2" other="unknownattributes">
<file name="file11" type="active"/>
<file name="file21" type="inactive"/>
<file name="file31" type="active"/>
<file name="file41" type="active"/>
<file name="file51" type="active"/>
</folder>
<folder name="pack3" other="unknownattributes">
<file name="file13" type="active"/>
</folder>
</root>
Code: Select all
<?xml version="1.0"?>
<root>
<folder name="pack1" other="unknownattributes">
<file name="file4" type="inactive"/>
<file name="file5" type="inactive"/>
</folder>
<folder name="pack2" other="unknownattributes">
<file name="file21" type="inactive"/>
</folder>
</root>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:copy-of select="//folder/file[@type='inactive']/parent::folder/parent::root" />
</xsl:template>
</xsl:stylesheet>