This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: merging with document()


Hello Jeff,

Jeff Shevlen wrote:
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()" />
The problem here are the params after the variables. Use variables for the documents too. Params are for parameterizing a template, variables are constants in this template.

  <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.
The template will find every node

<foo:overview/>

in the file, where the namespace prefix foo is bound to the namespace http://abc.com/xml/overview, which is in the XSLT bount prefix o.

On this element there must be an attribute foo:overviewID="bar".

The template looks ok from here, but without the XML it's a bit difficult to say whether it's really ok.

Regards,

Joerg

=================================

TIA,
Jeff

XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]