Page 1 of 1

Basic Xinclude question

Posted: Tue Sep 20, 2005 5:37 pm
by ggorman
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

Posted: Tue Sep 20, 2005 10:37 pm
by ggorman
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

Posted: Tue Sep 20, 2005 11:31 pm
by ggorman
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

Posted: Wed Sep 21, 2005 12:43 am
by ggorman
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

Posted: Wed Sep 21, 2005 8:17 am
by Radu
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.

Posted: Wed Sep 21, 2005 4:21 pm
by ggorman
Thanks Radu -- that would be the basic thing I was missing then. Works good now.

GG