Subject: Re: [xsl] merging with document() From: Joerg Heinicke <joerg.heinicke@xxxxxx> Date: Thu, 19 Sep 2002 09:06:56 +0200 |
Hi,
I want to merge, and otherwise compare and manipulate, multiple xml docs in one stylesheet. I've met with some success, but I'm having a lot of trouble too. I have couple of questions:
1. A general question about approach and best practice. I've played with 2 methods of reading in the files:
(1) reading the files into variables - nodesets - and working with the nodesets <xslt:variable name="file01" select="string(m:file01)" /> <xslt:variable name="file02" select="string(m:file02)" /> <xslt:variable name="file03" select="string(m:file03)" /> [ ... ] <xslt:param name="nodes01" select="document($file01,/*)/node()" /> <xslt:param name="nodes02" select="document($file02,/*)/node()" /> <xslt:param name="nodes03" select="document($file03,/*)/node()" />
(2) letting the templates sort it all out using apply-templates <xslt:apply-templates select = "document($file01)" /> [ ... ] <xslt:template match = "//element03"> [ ... ]
With regards to (1) I've found it awkward to navigate the nodesets to access the elements and attributes I want to test. I've been looking at a merge stylesheet found at http://www.informatik.hu-berlin.de/~obecker/XSLT/ - and it's been great - but he uses recursion to loop through the different nodesets, and I was wondering if there was a simpler way to do it.
Using the (2)nd approach seemed more straight forward to me - initially - but I ran into problems passing params around and trying to match similarly named elements in different source docs (see next question).
2. How do you use namespace prefixes to in match expressions properly. The following doesn't work and I assume it's something simple, but what I don't know.
<xslt:stylesheet version = "1.0" xmlns:xslt = "http://www.w3.org/1999/XSL/Transform" xmlns:m = "http://abc.com/xml/transforms/merge" xmlns:o = "http://abc.com/xml/overview" xmlns:r = "http://abc.com/xml/roles">
<xslt:template match = "m:merge"> <xslt:variable name="file01" select="string(m:file01)" /> <xslt:variable name="file02" select="string(m:file02)" /> <xslt:variable name="file03" select="string(m:file03)" />
<xslt:param name="o-nodes" select="document($file01,/*)/node()" /> <xslt:param name="r-nodes" select="document($file02,/*)/node()" /> <xslt:param name="s-nodes" select="document($file03,/*)/node()" />
<xslt:element name = "newdoc"> <xslt:attribute name = "newdoc_ID"> <xslt:value-of select = "newdoc_01'"/> </xslt:attribute> <xslt:apply-templates select = "document($file01)" /> </xslt:element> </xslt:template>
<xslt:template match = "//o:overview"> <xslt:message > <xslt:text />overview id = <xslt:value-of select = "@o:overviewID" /> </xslt:message> </xslt:template>
</xslt:stylesheet>
When I remove the "o:" prefixes things work just fine.
=================================
TIA, Jeff
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] merging with document(), Jeff Shevlen | Thread | RE: [xsl] merging with document(), Michael Kay |
Re: [xsl] Problem with using $varia, Jochen Metzger | Date | [xsl] <import> and WSDL, Roger Menday |
Month |