|
next
|
Subject: Re: Using a variable xpath Author: Minollo I. Date: 21 Jun 2001 03:24 PM
|
At 03:21 PM 6/21/2001 -0400, you wrote:
>From: "Chris Longfield"
>
>Hello,
> I would like to create an xpath as a variable and then apply it to a
> nodeset, returning only the nodes in the nodeset that meet the xpath
> conditions. I can't find this anywhere.
>for example, if I create
>{xsl:variable name='$magazines-about-fishing' }
>{xsl:call-template name='get-magazines-about-fishing-xpath' /}
>{/xsl:variable}
>then I cannot say :
>{xsl:for-each select='$node-set$magazines-about-fishing' }
>.
>.
>.
>nor can I say:
>document(/some_doc)$path_to_what_I_want
I'm not sure about what this last one might mean.
But you can say
{xsl:for-each select='$magazines-about-fishing'}
(actually you will probably say something like {xsl:for-each
select='$magazines-about-fishing/magazine'}, assuming the variable is
instantiated to something like {magazine
id=1}{title}myTitle1{/title}{/magazine}{magazine
id=2}{title}myTitle2{/title}{/magazine}
>Can anyone tell me a way around this? I would like to process xml to
>create the paths which I am going to use on my main data set. I could do
>this in a servlet by building the xpaths and writing queries (oops,
>XPath's in 3.0 ) with them, but it seems that xslt has a lot of good
>processing potential for dealing with the sets I get back.
As already noted in another thread, in XSLT 1.0 this is not supported;
MSXML and Xalan-J support a special node-set function that converts a
document fragment into a node-set; in Stylus Studio we have chosen to go in
the direction in which XSLT 2.0 specs are going, which is to transparently
treat rtfs as nodesets.
Hope this helps,
Minollo
|
next
|
Subject: Re: Using a variable xpath Author: Chris Longfield Date: 21 Jun 2001 05:12 PM
|
On 6/21/01 4:34:53 PM, Alex Lloyd wrote:
>It sounds like what you're
>trying to do is expand a
>string variable into an xpath
>expression and then have the
>XSLT processor evaluate that
>expression.
I would definitely be able to do what I want to do if that is the case - that is, the string variable gets treated like an xpath.
Under Stylus
>Studio and the Extensible
>Information Server nee Portal
>Server you can use the expr
>attribute instead of select.
>For example, {xsl:for-each
>expr='foo/bar[{@something="$ba
>z"]}'}.
This does not seem to be true (under Stylus at least) - I am getting an error saying I need a select attribute defined.
In addition, the example you give is not what I had in mind. In my scenario, the $baz variable would hold "/trucks/dealers[@city='Atlanta']"
which is probably not what your '@something' above was holding. Even if @something did hold that, it is not what I mean to do.
>
>Using standard XSLT, you could
>do this:
>{xsl:for-each
>select='foo/bar'}
>{xsl:if test="@baz =
>'{$jabootie}'"}
> whatever
> {/xsl:if}
> {/xsl:for-each}
>
>Alex Lloyd
>eXcelon corp.
In both of these examples, the stylesheet has to know something about the xml doc it is operating on (for example, that the xpath foo/bar exists ). What I would like to do is hand the stylesheet a set of nodes, and also some information saying that 'foo/bar' exists, and has an attribute I want to test against. I don't want to put the path 'foo/bar' in the stylesheet, because next time I might hand it a set of nodes that has only a 'trucks/dealers' path, and ask it to apply some conditions to that. The stylesheet I want to build doesn't know anything about it's target document. What it would know is how to read an xml document that describes the target document, and tells it what to look for in it. Then I can use this stylesheet no matter what my data model is, as long as the object (it's a servlet) requesting the operations knows about the data model and the description language.
Since I would like my description language to be written in xml, I thought stylesheet processing would be naturally amenable to this task. Are there any suggestions along these lines other than writing my own parser? (I have been avoiding lex/yacc my entire career :)
Chris
|
|
|
|