XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Chris LongfieldSubject: Using a variable xpath
Author: Chris Longfield
Date: 21 Jun 2001 03:16 PM
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

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.

Chris

Postnext
Minollo I.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

Postnext
Chris LongfieldSubject: Re: Using a variable xpath
Author: Chris Longfield
Date: 21 Jun 2001 03:51 PM

I'm not sure about what this last
>one might mean.
But you can say

>{xsl:for-each
>select='$magazines-about-fishing'}
(actu
>ally you will probably say something
>like {xsl:for-each
>
select='$magazines-about-fishing/magazi
>ne'}, assuming the variable is
>
instantiated to something like
>{magazine
>
id=1}{title}myTitle1{/title}{/magazine}
>{magazine
>
id=2}{title}myTitle2{/title}{/magazine}
>

>Minollo

Right. But the thing I am getting into the variable is not a node set, but rather is an xpath expression ( a string ), which I then want to use to apply to some document or node set as a filter. Perhaps I am going about it the wrong way, since variables tend to hold nodes, and literal values like strings are always literal values.

So what would be a good way of attacking this problem: I would really like to use an xml document to describe the elements that the stylesheet should return. So:
{query}
{document}cars.xml{/document}
{path}
{element}trucks{/element}
{element}dealers{/element}
{condition}
{attribute}city{/attribute}
{value}Atlanta{/value}
{/condition}
{/path}
{/query}

might describe the xpath:
/trucks/dealers[@city='Atlanta']
to be applied to the document held in "cars.xml"

Clearly, I am not wedded to the path representation being reduced to a String if that does not get me the stuff I want out of 'cars.xml', but it would be nice if I could create a variety of queries that a single stylesheet could apply without the stylesheet knowing anything about the structure of the target document. The stylesheet would only have to know about my little query language to return items.

Any suggestions on how to accomplish something like this in XSLT?

Chris



Postnext
(Deleted User) Subject: Re: Using a variable xpath
Author: (Deleted User)
Date: 21 Jun 2001 04:34 PM
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. 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="$baz"]}'}.

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.

Postnext
Chris LongfieldSubject: 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

Postnext
(Deleted User) Subject: Re: Using a variable xpath
Author: (Deleted User)
Date: 21 Jun 2001 05:45 PM
I brushed up on my use of expr. It only works on xsl:variable, so:

{xsl:variable name='querySet' expr='{$queryStr}'/}
{xsl:for-each select='$querySet'}

You seem to understand how to produce your query string, and this example should help you execute that query.

--Alex

Postnext
Chris LongfieldSubject: Re: Using a variable xpath
Author: Chris Longfield
Date: 21 Jun 2001 05:18 PM

So, perhaps a little more clearly, where your expression says:
{xsl:for-each expr='foo/bar[{@something="$baz"]}'
where $baz might = 'Atlanta',
I am asking to do something like (the illegal):
{xsl:for-each select="{$BAZ}" }
where BAZ="/trucks/dealers[@location='Atlanta']"

Any ideas?

Postnext
(Deleted User) Subject: Re: Using a variable xpath
Author: (Deleted User)
Date: 21 Jun 2001 05:35 PM
Are you saying baz contains a string equal to your desired select expression?

--Alex

Posttop
Chris LongfieldSubject: Re: Using a variable xpath
Author: Chris Longfield
Date: 22 Jun 2001 09:16 AM
On 6/21/01 5:35:32 PM, Alex Lloyd wrote:
>Are you saying baz contains a
>string equal to your desired
>select expression?
>
>--Alex

Yes.


 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.