remove include
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Thu Nov 09, 2006 12:55 pm
remove include
Hi,
I have a xml file (my main file) with includes. I want to remove those include lines and put the code of those include files into my main file. How can I do that with xslt?
Example:
Main file:
<definitions>
<types>
<schema>
<include file="includefile.xml"/>
</schema>
<z>
<x>XXX</x>
</z>
<y>
<x>XXX</x>
</y>
</types>
</definitions>
Include file:
<definitions>
<types>
<schema>
<a>AAA</a>
<b>BBB</b>
<c>CCC</c>
</schema>
</types>
</definitions>
Result:
<definitions>
<types>
<schema>
<a>AAA</a>
<b>BBB</b>
<c>CCC</c>
</schema>
<z>
<x>XXX</x>
</z>
<y>
<x>XXX</x>
</y>
</types>
</definitions>
I have a xml file (my main file) with includes. I want to remove those include lines and put the code of those include files into my main file. How can I do that with xslt?
Example:
Main file:
<definitions>
<types>
<schema>
<include file="includefile.xml"/>
</schema>
<z>
<x>XXX</x>
</z>
<y>
<x>XXX</x>
</y>
</types>
</definitions>
Include file:
<definitions>
<types>
<schema>
<a>AAA</a>
<b>BBB</b>
<c>CCC</c>
</schema>
</types>
</definitions>
Result:
<definitions>
<types>
<schema>
<a>AAA</a>
<b>BBB</b>
<c>CCC</c>
</schema>
<z>
<x>XXX</x>
</z>
<y>
<x>XXX</x>
</y>
</types>
</definitions>
-
- Posts: 89
- Joined: Mon Mar 06, 2006 10:13 pm
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="include">
<xsl:copy-of select="document(@file)//*[name()=name(current()/..)]/*"/>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The default template (match="*") just copies everything and recurses on it's children.
We create a template for include. When we reach this template, we use the document function to access the linked document.
The //*[name()=name(current()/..)]/* is to change the scope of the elements we copy from that document.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="include">
<xsl:copy-of select="document(@file)//*[name()=name(current()/..)]/*"/>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The default template (match="*") just copies everything and recurses on it's children.
We create a template for include. When we reach this template, we use the document function to access the linked document.
The //*[name()=name(current()/..)]/* is to change the scope of the elements we copy from that document.
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