Basic Xinclude question
Questions about XML that are not covered by the other forums should go here.
Basic Xinclude question
I'm having some trouble understanding how Xinclude should work. By the examples on http://www.w3.org, I think this should work to include all of the file bfile.xml in axml.xml. I'm thinking it will find bfile.xml in the same directory as afile.xml
afile.xml:
<?xml version="1.0" encoding="UTF-8"?>
<forest xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="bfile.xml" />
<tree><name>oak</name></tree>
<tree><name>elm</name></tree>
</forest>
bfile.xml:
<?xml version="1.0" encoding="UTF-8"?>
<residents>
<animal><name>bear</name></animal>
<animal><name>weasel</name></animal>
<animal><name>wizard</name></animal>
</residents>
ab.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
</xsl:stylesheet>
Running ab.xsl on afile.xml results in oak and elm only. Whereas running ab.xsl on this file results in the residents first, then the trees:
<?xml version="1.0" encoding="UTF-8"?>
<forest xmlns:xi="http://www.w3.org/2001/XInclude">
<residents>
<animal><name>bear</name></animal>
<animal><name>weasel</name></animal>
<animal><name>wizard</name></animal>
</residents>
<tree><name>oak</name></tree>
<tree><name>elm</name></tree>
</forest>
I think I'm missing something basic here?
thanks for any advice -- GeorgeG
afile.xml:
<?xml version="1.0" encoding="UTF-8"?>
<forest xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="bfile.xml" />
<tree><name>oak</name></tree>
<tree><name>elm</name></tree>
</forest>
bfile.xml:
<?xml version="1.0" encoding="UTF-8"?>
<residents>
<animal><name>bear</name></animal>
<animal><name>weasel</name></animal>
<animal><name>wizard</name></animal>
</residents>
ab.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
</xsl:stylesheet>
Running ab.xsl on afile.xml results in oak and elm only. Whereas running ab.xsl on this file results in the residents first, then the trees:
<?xml version="1.0" encoding="UTF-8"?>
<forest xmlns:xi="http://www.w3.org/2001/XInclude">
<residents>
<animal><name>bear</name></animal>
<animal><name>weasel</name></animal>
<animal><name>wizard</name></animal>
</residents>
<tree><name>oak</name></tree>
<tree><name>elm</name></tree>
</forest>
I think I'm missing something basic here?
thanks for any advice -- GeorgeG
After some more research, I found a method of putting include in the xsl instead of the xml -- that seems more like the correct place. Still can't make it work though. I have this now
afile.xml
<?xml version="1.0" encoding="UTF-8"?>
<forest >Forest element
<tree><name>oak</name></tree>
<tree><name>elm</name></tree>
</forest>
bfile.xml
<residents>Residents element
<animal><name>bear</name></animal>
<animal><name>weasel</name></animal>
<animal><name>wizard</name></animal>
</residents>
aincludesb.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="bfile.xml" />
<xsl:template match="/">
<xsl:text>
</xsl:text><xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
This XSL results in this:
<?xml version="1.0" encoding="utf-8"?>
Forest element
oak
elm
Any ideas about how I can reference the elements under residents?
GG
afile.xml
<?xml version="1.0" encoding="UTF-8"?>
<forest >Forest element
<tree><name>oak</name></tree>
<tree><name>elm</name></tree>
</forest>
bfile.xml
<residents>Residents element
<animal><name>bear</name></animal>
<animal><name>weasel</name></animal>
<animal><name>wizard</name></animal>
</residents>
aincludesb.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="bfile.xml" />
<xsl:template match="/">
<xsl:text>
</xsl:text><xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
This XSL results in this:
<?xml version="1.0" encoding="utf-8"?>
Forest element
oak
elm
Any ideas about how I can reference the elements under residents?
GG
More experimenting .. I changed <xi:include ref="bfile.xml"/> to <xsl:include href="bfile.xml"/>. The popup help in Oxygen says the file will be parsed as an xml document and the children of that document will replace the include statement in this one. Exactly what I'm looking for -- I think. But when I run the transform, I get this message -- Oxygen is wanting it to be a stylesheet, not xml, after all?
SystemID: D:\cmtest\bc\Xinclude\aincludeb.xsl
Location: 3:0
Description: E The supplied file does not appear to be a stylesheet
GG
SystemID: D:\cmtest\bc\Xinclude\aincludeb.xsl
Location: 3:0
Description: E The supplied file does not appear to be a stylesheet
GG
I've found a way to do what I need using document(). I still don't know why my xinclude incantation doesn't work; but this xsl works on the afile.xml I posted last
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="forest">
<!-- applies bfile.xml templates -->
<xsl:apply-templates select="document('bfile.xml')" />
<!-- applies afile.xml templates -->
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
Giving these results:
<?xml version="1.0" encoding="utf-8"?>Residents element
bear
weasel
wizard
Forest element
oak
elm
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="forest">
<!-- applies bfile.xml templates -->
<xsl:apply-templates select="document('bfile.xml')" />
<!-- applies afile.xml templates -->
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
Giving these results:
<?xml version="1.0" encoding="utf-8"?>Residents element
bear
weasel
wizard
Forest element
oak
elm
Dear George
The right way to use XInclude is the way described in your first post with files afile.xml and bfile.xml. You just have to go to the Options Menu -> Preferences -> XML Parser Options and select the "Enable XInclude" checkbox.
You can read more about the XInclude support in Oxygen here:
http://www.oxygenxml.com/xinclude_support.html
Or you can just press F1 in the Preferences Dialog to see a detailed explanation of Oxygen Preferences.
Hope this helps
Regards, Radu.
The right way to use XInclude is the way described in your first post with files afile.xml and bfile.xml. You just have to go to the Options Menu -> Preferences -> XML Parser Options and select the "Enable XInclude" checkbox.
You can read more about the XInclude support in Oxygen here:
http://www.oxygenxml.com/xinclude_support.html
Or you can just press F1 in the Preferences Dialog to see a detailed explanation of Oxygen Preferences.
Hope this helps
Regards, Radu.
Return to “General XML Questions”
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