1 + 1 (included) XML file … 2 XSL … 1 Ant buildfile

Here should go questions about transforming XML with XSLT and FOP.
Zearin
Posts: 107
Joined: Mon Jul 30, 2007 11:31 pm
Location: College Park, MD, United States

1 + 1 (included) XML file … 2 XSL … 1 Ant buildfile

Post by Zearin »

So, I have 2 XML files with an XSL file for each one. I've performed these transformations individually and everything works AOK.

So now I have one XML file including the second one, but I still want the second one to use its own stylesheet--not the parent's stylesheet.

Finally, I'm learning Ant (which is also written in XML!) to perform the transformations. I'm finding it very useful, but I thought it was important to mention it if anybody knows what it can (or cannot) do.

Help?
-- Zearin
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

Have you tried using <xsl:import> or <xsl:include> to include the other stylesheet?

http://www.w3schools.com/xsl/el_include.asp

If the 2 xml files are totally different, (they don't have any of the same elements), then you will probably be able to just include the 2nd stylesheet and have it work correctly.

Otherwise, you may have to edit your 2nd stylesheet to use mode's, and your parent stylesheet to call templates using this new mode.
eg <xsl:apply-templates mode="secondary"/>
http://www.w3schools.com/xsl/el_apply-templates.asp
Zearin
Posts: 107
Joined: Mon Jul 30, 2007 11:31 pm
Location: College Park, MD, United States

Hmm...

Post by Zearin »

Well, I'm now trying to import the second stylesheet, and it does not appear to have any effect on the output at present.

The import statement is:

Code: Select all

<xsl:import href="transcript.xsl" />
And the included XML file is included like so:

Code: Select all

<xi:include href="transcript.xml" />
The two XML files are NOT the same. The first (parent) document is in Docbook 5 RC5. The second is an XML file that adheres to a custom XML Schema I wrote.

While I understand the very very basics of namespaces, I admit I'm a little confused as to what goes where in this case. Currently, my custom XML document has the following root element:

Code: Select all


<transcript 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="transcript.xsd"
>
How this affects whether or not the stylesheets use prefixes or not is not yet in my realm of understanding. I suspect this as a possible culprit. Does anyone know what needs fixing?
-- Zearin
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

Could it be that the 2nd xml file is not being included when transforming??

You could try the following: (you'd have to declare the xi namespace in your xsl)
<xsl:template match="xi:include">
<xsl:apply-templates select="document(@href)"/>
</xsl:template>

http://www.w3schools.com/xsl/func_document.asp
Zearin
Posts: 107
Joined: Mon Jul 30, 2007 11:31 pm
Location: College Park, MD, United States

Topic split. :)

Post by Zearin »

Hehe…

As my investigation continued I realized this was not necessarily an XSLT-specific problem--I believe it has something to do with Ant. (I think.)

I started this topic again in General XML Questions, where I did something like what you suggested.

So it was good advice! Thanks. 8)

Technically, though, I shouldn't have to do this, right? It seems like a workaround. And it does its job nicely--but I would like to get the XInclude to "just work" and have the stylesheet transform the entire document (includes and all) without having to rely on a template for XInclude statements.
-- Zearin
Post Reply