On Feb 21, 3:43 pm, "Johan" <joh...@gmail.com> wrote:
> On 21 feb, 13:51, p.le...@ctncorp.com wrote:
> > On Feb 21, 2:14 pm, "Johan" <joh...@gmail.com> wrote:
> > > On 21 feb, 11:30, p.le...@ctncorp.com wrote:
> > > > <xsl:stylesheet version="1.0"
> > > > xmlns
sl="http://www.w3.org/1999/XSL/Transform">
> > > > <xsl:variable
> > > > name="lib"
> > > > select=
> > > > "
> > > > document(concat('xform_lib_',/root/@library,'.xml'))
> > > > "/>
> > > > <xsl:template match="root">
> > > > <result>
> > > > <xsl:apply-templates/>
> > > > </result>
> > > > </xsl:template>
> > > > <xsl:template match="design">
> > > > <xsl:value-of
> > > > select="$lib/library/design[@n=current()]"/>
> > > > </xsl:template>
> > > > </xsl:stylesheet>
>
> > > I will describe my problem in a little bit more
> > > detail: The <library> element contains one or more
> > > <type> elements. Each type has an "id" attribute. The
> > > author of the design.xml file can use type's from the
> > > library by referring to their id.
>
> > Depending on exact way the author may 'use' the types
> > from the library, this might look similar to the
> > following:
>
> > <xsl:template match="refer-to-lib-type">
> > <xsl:apply-templates
> > select="$lib/library/type[@id=current()/@id]"/>
> > </xsl:template>
> I don't have templates that match the library (or the
> types inside it), so
> <xsl:apply-templates
> select="$lib/library/type[@id=current()/@id]"/>
> isn't going to match anything.
Create the templates to match the library elements, then.
It's good design anyway.
> I think the solution from fildpauz fits my needs the
> best:
>
> <xsl:template match="root">
> <xsl:apply-templates select="design"/>
> <xsl:apply-templates select="document(library.xml)/"/>
> </xsl:template>
You don't seem to understand how this solution would work.
As you yourself said, you don't have any templates that
would match the elements within your library, so
apply-templates select="document('library.xml')" would
merely apply the default templates to this nodeset.
> The only question that remains is this one:
> "How can I perform xsl:apply-templates to the union of
> the design and the library together?
You cannot achieve the results identical to using XInclude,
period. You may attempt to do something like
<xsl:variable
name="everything" select="/|document('foo')"/>
but even if it works for you, I doubt it would really solve
your problems. You seem to be way over your head as it is,
and if you try juggling nodesets without accidentally
converting them to rtfs and ending you days in an asylum
due to the sheer frustration of it, you're bound to drown.
> (There aren't any templates that directly match elements
> in the library. There template that matches the design
> element gets values from the library when it needs them
> (using <xsl:variable name="..." select="...">)). "
So? I believe I explained to you how to write XPath
expressions accessing other documents, it doesn't matter
whether you use them to apply templates, grab values or
populate variables. Either you want to do it the easy way
(in that case, deal with it--there's no easy way short of
XSLT2, and no, existing browsers do not support that) or
you don't really understand what's going on (and in that
case perhaps you should stop tinkering with real projects
before you break something, and start tinkering with toy
projects).
--
Pavel Lepin