This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: variables
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] variables
- From: "Michael Beddow" <mbnospam at mbeddow dot net>
- Date: Thu, 31 May 2001 17:27:49 +0100
- References: <55CB9FEAE87DD411A83200508BDF0DFE06D1D9@himail8.hi.bosch.de>
- Reply-To: xsl-list at lists dot mulberrytech dot com
-------------------------------------------------
Michael Beddow
http://www.mbeddow.net/
----- Original Message -----
From: "Mengel Andre (FV/SLM) *" <Andre.Mengel@de.bosch.com>
To: <xsl-list@lists.mulberrytech.com>
Sent: Thursday, May 31, 2001 1:23 PM
Subject: AW: [xsl] variables
> Hi Jeni,
>
> thank you for your very detailed description and
> spending much time concerning my issue.
> However there is one thing I don't understand.
> In your "evaluate-paths"-template you used the
> <xsl:copy-of> instruction in order to return a
> copy of the result nodes (s. a) ) which will be
> the RTF of the "var1-rtf" variable. Is this right ?
> I thought that the result of the <xsl:copy-of>
> instruction would be copied directly into the result-tree.
> Could you please give me an answer to that question.
>
> Thank you for your efforts,
>
> best regards
>
> André Mengel
>
>
> > -----Ursprüngliche Nachricht-----
> > Von: Jeni Tennison [mailto:mail@jenitennison.com]
> > Gesendet: Donnerstag, 31. Mai 2001 13:13
> > An: Mengel Andre (FV/SLM) *
> > Cc: xsl-list@lists.mulberrytech.com
> > Betreff: Re: [xsl] variables
> >
> >
> > Hi André,
> >
> > > I want to create one variable that contains all nodes of the
> > > source-document specified by the loction-paths in the
path-elements
> > > (path1,path2,...).
> > >
> > > I know how to do this with one path-element (e.g. path1), the
> > > solution would be
> > >
> > > <xsl:variable name="doc2" select="document('doc2.xml)">
> > > <xsl:variable name="var1"
> > select="xalan:evaluate(string($doc2/path1))">.
> > >
> > > But I don't know how to do this with more than one path-element. A
> > > restriction is that the number of path elements could vary. Any
help
> > > would be welcome. Thanks in advance
> >
> > Well, you can build a recursive template that takes two arguments -
> > the paths that you want to evaluate and the current result of
> > evaluating the paths:
> >
> > <xsl:template name="evaluate-paths">
> > <xsl:param name="paths" select="document('doc2.xml')/paths/*" />
> > <xsl:param name="result" select="/.." />
> > ...
> > </xsl:template>
> >
> > [Note: it's not clear what the structure of 'doc2.xml' is, so I've
> > assumed that it's got 'paths' as a document element and that the
paths
> > are specified in elements of various names underneath that - you may
> > want to change that location path.]
> >
> > Within the template, if you have no more paths to evaluate, then
> > you're done, and you can set the variable to the result, and use
that
> > variable in whatever way you need to use it:
> >
> > <xsl:template name="evaluate-paths">
> > <xsl:param name="paths" select="document('doc2.xml')/paths/*" />
> > <xsl:param name="result" select="/.." />
> > <xsl:choose>
> > <xsl:when test="not($paths)">
> > <xsl:variable name="var1" select="$result" />
> > ...
> > </xsl:when>
> > <xsl:otherwise>
> > ...
> > </xsl:otherwise>
> > </xsl:choose>
> > </xsl:template>
> >
> > Otherwise, you want to move on to the next recursion by unioning the
> > result of evaluating the first path in the set to the result that
you
> > have so far, and removing that path from the set of paths left to
> > evaluate:
> >
> > <xsl:template name="evaluate-paths">
> > <xsl:param name="paths" select="document('doc2.xml')/paths/*" />
> > <xsl:param name="result" select="/.." />
> > <xsl:choose>
> > <xsl:when test="not($paths)">
> > <xsl:variable name="var1" select="$result" />
> > ...
> > </xsl:when>
> > <xsl:otherwise>
> > <xsl:call-template name="evaluate-paths">
> > <xsl:with-param name="paths"
> > select="$paths[position() > 1]" />
> > <xsl:with-param name="result"
> > select="$result |
> > xalan:evaluate($paths[1])" />
> > </xsl:call-template>
> > </xsl:otherwise>
> > </xsl:choose>
> > </xsl:template>
> >
> > Note that you have to use the value of the $var1 variable (holding
the
> > result of evaluating all the paths) within the template itself -
> > there's no way of returning this value to have it held within a
> > variable as a node set unless:
> >
> > (a) you don't care about the context those nodes are in, in which
> > case you could have the template return a copy of the result
> > nodes:
> >
> > <xsl:when test="not($paths)">
> > <xsl:copy-of select="$result" />
> > </xsl:when>
> >
> > and have the $var1 variable be set to the result of calling
the
> > template and converting the result to a node set:
> >
> > <xsl:variable name="var1-rtf">
> > <xsl:call-template name="evaluate-paths" />
> > </xsl:variable>
> > <xsl:variable name="var1" select="xalan:nodeSet($var1-rtf)" />
> >
> > (b) you're prepared to go to extraordinary lengths to reaccess the
> > actual nodes - you can return an RTF of node elements that use
> > the unique generated ID of the nodes to identify the nodes
that
> > you actually want, and then resolve those generated IDs to
find
> > the nodes you're after.
> >
> > (b) you can use a processor that supports EXSLT - Functions, in
> > which case you can use the same kind of code to define a
> > function and return the result of calling that function as a
> > node set for the $var1 variable.
> >
> > I hope that helps,
> >
> > Jeni
> >
> > ---
> > Jeni Tennison
> > http://www.jenitennison.com/
> >
> >
> >
> > XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
> >
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list