This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Getting at original document from inside document()
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Getting at original document from inside document()
- From: Oleg Tkachenko <olegt at multiconn dot com>
- Date: Tue, 23 Oct 2001 15:53:09 +0200
- Organization: Multiconn International
- References: <200110231324.f9NDOca15577@shelob.julianhaight.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Phil Endecott wrote:
> Dear XSL experts,
>
> Once I am in a document selected by a document() function, is there
> any way to refer to nodes in the original source document?
>
> Here's a (contrived) example: I have this as my main source document:
>
> <book title="foo">
> <chapter src="chap1.xml"/>
> </book>
>
> Then I have a stylesheet that does something like:
>
> <xsl:template match="chapter">
> <xsl:apply-templates select="document(@src)/*"/>
> </xsl:template>
>
> and then somewhere deep in the processing of the chapter's contents I
> want to use the book's title. At first I naively tried /book/@title -
> but that doesn't work, because / is the root of chap1.xml, not of the
> source document. I could use document('....')/book/@title, if I knew
> what the name of the original source file was: but I don't.
>
> I was hoping that something like document('')/book/@title would get
> the answer, but it looks like this gets the stylesheet, not the
> original input document.
>
> Of course there are various hacks to get or fix the filename that
> could have the desired effect, but I was hoping that someone would
> know of a "clean" way to do this.
>
> Any ideas anyone?
You can save root of original source document in a global variable and
use it anywhere you want like ...select="$root/book/chapter".
--
Oleg Tkachenko
Multiconn International, Israel
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list