Parent Branch Selection
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 3
- Joined: Wed Nov 08, 2006 4:44 pm
Parent Branch Selection
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>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Start with a default copy template and add a another template that maches elements. Then check if the element is an inactive file or if that element contains an inactive file and only then copy the element to the outout. Full example below
Best Regards,
George
Code: Select all
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*" priority="10">
<xsl:if test="self::file[@type='inactive'] or .//file[@type='inactive']">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
George
George Cristian Bina
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service