Re: [xsl] <xsl:apply-imports/> with select attribute

Subject: Re: [xsl] <xsl:apply-imports/> with select attribute
From: "Tony Graham" <tgraham@xxxxxxxxxx>
Date: Thu, 19 Dec 2013 14:22:02 -0000 (GMT)
On Thu, December 19, 2013 12:35 pm, Christian Mahnke wrote:
>> What would you want this construct to actually do?
>
> My use case is as follows: Ive got a master template, in which the
> template @match="/" contains a <xsl:for-each/> over a collection(). Inside
> the loop I would like to call templates from imported stylesheets, that
> are designed to handle single documents. Additionally they havent be
> designed to run together with other templates, so they contain no @mode
> attribute on their template @match="/".

So it sounds like you can't or don't want to modify those stylesheets.

> This way the calls to <xsl:apply-templates select="./> (where . is a
> document node from the collection) doesnt match the root template of the
> imported stylesheet, but the root template of the master stylesheet, which
> causes a unwanted loop.
>
> Im just looking for a way to be able to give the imported stylesheets a
> higher priority when Im looping to a collection of files.

Are you able to start from an initial named template rather than matching
on '/' in your initial stylesheet?  If so, and if there's no template for
'/', then you can just use xsl:apply-templates.

If you were able to match on the document element instead of the document
node, you could potentially do the same.

If your source XML uses a different document element name from the
documents in the collection, then you could use a more specific match
pattern, e.g., '/name-of-source-document-element' and use
xsl:apply-templates to process the documents in the collection.

Current Thread