Remove group levels
Here should go questions about transforming XML with XSLT and FOP.
Remove group levels
I have XML that contains elements that contain other elements but not values, they all have 'Group' in the element name. Is it possible to remove the tags that contain 'Group'; found the function syntax:
not(contains(name(),'Group') - i'm not sure where it would go?
Here is my current xsl:
not(contains(name(),'Group') - i'm not sure where it would go?
Code: Select all
<my:BestPracticeGroup>
<my:BPRepeatSection>
<my:BPDetails>Complete central line insertion checklist in real time</my:BPDetails>
<my:ActionsGroup>
<my:ActionsTable>
my:DateImplementBP>2012-02-02</my:DateImplementBP>
<my:DateCompleteBP>2012-03-02</my:DateCompleteBP>
</my:ActionsTable>
<my:ActionsTable>
</my:ActionsTable>
</my:ActionsGroup>
</my:BPRepeatSection>
</my:BestPracticeGroup>
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:output method="xml" indent="no"/>
<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
</xsl:stylesheet>
Re: Remove group levels
You can start with a recursive copy template and just add a rule that matches the elements ending with 'Group' for example and do the specific process you need there. In the example below we just apply templates on their content, thus removing that element but keeping its content:
Regards,
George
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[ends-with(name(), 'Group')]">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
George
George Cristian Bina
Re: Remove group levels
Great. I went with contains(). FYI: Got error with ends-with()
Engine name: Saxon6.5.5
Severity: warning
Description: Error in expression *[ends-with(name(), 'Group')]: Unknown system function: ends-with
Engine name: Saxon6.5.5
Severity: warning
Description: Error in expression *[ends-with(name(), 'Group')]: Unknown system function: ends-with
Re: Remove group levels
Hi,
The stylesheet has the version 2.0, so it won't work with Saxon 6.5.5.
When you try to apply the transformation, Oxygen even gives you a confirmation message and recommends changing the processor to Saxon-HE/PE/EE.
Edit the transformation scenario: Document -> Transformation -> Configure Transformation Scenario, Edit and change the Transformer to Saxon-PE.
Regards,
Adrian
The stylesheet has the version 2.0, so it won't work with Saxon 6.5.5.
When you try to apply the transformation, Oxygen even gives you a confirmation message and recommends changing the processor to Saxon-HE/PE/EE.
Edit the transformation scenario: Document -> Transformation -> Configure Transformation Scenario, Edit and change the Transformer to Saxon-PE.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
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