Re: dynamic node selection
Hi Guys (Joerg, Conal, Alex & Tony) Thanks very much for the help, I should be able to get the particular fragments of xsl refactored now. Cheers, Ad. = Adam Flegman - Senior Software Engineer Mobile: (0414) 375 735 Phone: (07) 5547 8530 Facsimile: (07) 5547 8532 Email #1: [EMAIL PROTECTED] Email #2: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamic node selection
Maybe I'm petty, but ... Conal Tuohy wrote: if $parent="foo" and $child="bar" then: /*[local-name()=$parent][*[local-name()=$child]] should return all nodes matching the XPath "/foo" and having a child node named "bar". /*[local-name()=$parent]/*[local-name()=$child] should return all nodes which match the xpath "/foo/bar" Cheers Con Joerg - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: dynamic node selection
NB to avoid problems namespaces you might want to use the local-name() function instead of the name() function. e.g. if $parent="foo" and $child="bar" then: /*[local-name()=$parent][*[local-name()=$child]] should return all nodes which match the xpath "/foo/bar" Cheers Con > -Original Message- > From: Adam Flegman [mailto:[EMAIL PROTECTED] > Sent: Thursday, 24 July 2003 1:28 p.m. > To: [EMAIL PROTECTED] > Subject: Re: dynamic node selection > > > > Have you tried using name() function like: > > > > > select="/*[name()=$parentNode]/*[name()=$childNode]"/> > > > > However, as far as I know name() function is there for > > "emergency" cases, rather than normal usage. > > > > If you know what the nodes might be, you might want to > > use several stylesheets and pick the right stylesheet > > dynamically. > > Hi Alex, > > In some cases I actually had the node corresponding to the > parent and tried > using the name() function to match the $childNode portion but > it still didn't > work. > > select="$parentNode/*[name()=$childNode]" > > ($parentNode is an actual node, $childNode was the name of > the desired target > node below the parent). > > > I was hoping to use this approach to help cleanup/refactor > some verbose xslt > code I have inheirited. Its not really a critical problem as > the existing code > is functionally correct, I was just trying to tidy it up a bit. > > > > Ad. > > > = > Adam Flegman - Senior Software Engineer > > Mobile: (0414) 375 735 > Phone: (07) 5547 8530 > Facsimile: (07) 5547 8532 > Email #1: [EMAIL PROTECTED] > Email #2: [EMAIL PROTECTED] > > __ > Do you Yahoo!? > Yahoo! SiteBuilder - Free, easy-to-use web site design software > http://sitebuilder.yahoo.com > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamic node selection
Hi Adam, I don't think select="$parentNode/ will work. You cannot use variables in place of element names. Alex --- Adam Flegman <[EMAIL PROTECTED]> wrote: > > Have you tried using name() function like: > > > > > > select="/*[name()=$parentNode]/*[name()=$childNode]"/> > > > > However, as far as I know name() function is there > for > > "emergency" cases, rather than normal usage. > > > > If you know what the nodes might be, you might > want to > > use several stylesheets and pick the right > stylesheet > > dynamically. > > Hi Alex, > > In some cases I actually had the node corresponding > to the parent and tried > using the name() function to match the $childNode > portion but it still didn't > work. > > select="$parentNode/*[name()=$childNode]" > > ($parentNode is an actual node, $childNode was the > name of the desired target > node below the parent). > > > I was hoping to use this approach to help > cleanup/refactor some verbose xslt > code I have inheirited. Its not really a critical > problem as the existing code > is functionally correct, I was just trying to tidy > it up a bit. > > > > Ad. > > > = > Adam Flegman - Senior Software Engineer > > Mobile: (0414) 375 735 > Phone: (07) 5547 8530 > Facsimile: (07) 5547 8532 > Email #1: [EMAIL PROTECTED] > Email #2: [EMAIL PROTECTED] > > __ > Do you Yahoo!? > Yahoo! SiteBuilder - Free, easy-to-use web site > design software > http://sitebuilder.yahoo.com > > - > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamic node selection
> Have you tried using name() function like: > > select="/*[name()=$parentNode]/*[name()=$childNode]"/> > > However, as far as I know name() function is there for > "emergency" cases, rather than normal usage. > > If you know what the nodes might be, you might want to > use several stylesheets and pick the right stylesheet > dynamically. Hi Alex, In some cases I actually had the node corresponding to the parent and tried using the name() function to match the $childNode portion but it still didn't work. select="$parentNode/*[name()=$childNode]" ($parentNode is an actual node, $childNode was the name of the desired target node below the parent). I was hoping to use this approach to help cleanup/refactor some verbose xslt code I have inheirited. Its not really a critical problem as the existing code is functionally correct, I was just trying to tidy it up a bit. Ad. = Adam Flegman - Senior Software Engineer Mobile: (0414) 375 735 Phone: (07) 5547 8530 Facsimile: (07) 5547 8532 Email #1: [EMAIL PROTECTED] Email #2: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamic node selection
Hello Adam, My apologies for the lack of clarity. I was trying to use the value I have calcualted for the $targetNode variable to select a node in my XML document. If I had an xml source like the following, I would like to be able to 'dynamically' select nodes for processing. ... The xslt template to do the processing: ... do the processing if you know the path as exact as above (i.e. step by step) you can simply do something like For example if parameters parentNode = "foo" and childNode = "bar", then $targetNode would evaluate to the string "foo/bar". I would want the 'for-each' statement to select all the "bar" nodes under the "foo" parent node. I think the only step I am missing is how to write a xpath node selection query that can take a string parameter as its argument. If you want to evaluate more complex XPathes and can't find a work around the are processor specific extension functions like http://xml.apache.org/xalan-j/extensionslib.html#evaluate or a bit more common http://www.exslt.org/dyn/functions/evaluate/index.html. Regards, Joerg - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamic node selection
Hi Adam, Have you tried using name() function like: However, as far as I know name() function is there for "emergency" cases, rather than normal usage. If you know what the nodes might be, you might want to use several stylesheets and pick the right stylesheet dynamically. Cheers, -Alex --- Adam Flegman <[EMAIL PROTECTED]> wrote: > Hi Guys, > > I have been trying to re-factor some existing xslt > code and wonder if it is > possible to select nodes based on a string. > > The string is built up by parameters so the value of > the target node is > determined each time the xsl template is called. I > am having trouble using the > string to select the target node. In the sample > below I can calculate the name > of the target node I am after, but I am unsure how > to convert the name into an > actual node. > > > > > > > name="targetNode" > > select="concat(name($listNode),'/',$listItem)" /> > > > >... do the processing > > > > Any advice, greatly appreciated. > > > Adam. > > = > Adam Flegman - Senior Software Engineer > > Mobile: (0414) 375 735 > Phone: (07) 5547 8530 > Facsimile: (07) 5547 8532 > Email #1: [EMAIL PROTECTED] > Email #2: [EMAIL PROTECTED] > > __ > Do you Yahoo!? > Yahoo! SiteBuilder - Free, easy-to-use web site > design software > http://sitebuilder.yahoo.com > > - > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: dynamic node selection
--- Conal Tuohy <[EMAIL PROTECTED]> wrote: > Adam there's no "dynamic" xpath expression evaluation in XSLT - you'll > probably want to find some other way to identify the nodes you want to deal > with since writing a generic xpath evaluator in XSLT is not going to be easy. > It would be feasible though to parse some standard type of expressions rather > than any arbitrary xpath. e.g. if you could ensure that all the xpaths were > like: "foo[1]/blah[2]" - but this may not be feasible since you say you don't > know the possible values that your xpath expression may have? Where do they > come from? Hi Conal, I was getting the feeling that this was the case (i.e no dynamic xpath evaluation). I guess I have to go back and look at other ways to achieve a similar result. Thanks again to you and Tony for your help. Regards, Adam. = Adam Flegman - Senior Software Engineer Mobile: (0414) 375 735 Phone: (07) 5547 8530 Facsimile: (07) 5547 8532 Email #1: [EMAIL PROTECTED] Email #2: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: dynamic node selection
--- Conal Tuohy <[EMAIL PROTECTED]> wrote: > Adam there's no "dynamic" xpath expression evaluation in XSLT - you'll > probably want to find some other way to identify the nodes you want to deal > with since writing a generic xpath evaluator in XSLT is not going to be easy. > It would be feasible though to parse some standard type of expressions rather > than any arbitrary xpath. e.g. if you could ensure that all the xpaths were > like: "foo[1]/blah[2]" - but this may not be feasible since you say you don't > know the possible values that your xpath expression may have? Where do they > come from? Hi Conal, I was getting the feeling that this was the case (i.e no dynamic xpath evaluation). I guess I have to go back and look at other ways to achieve a similar result. Thanks again to you and Tony for your help. Regards, Adam. = Adam Flegman - Senior Software Engineer Mobile: (0414) 375 735 Phone: (07) 5547 8530 Facsimile: (07) 5547 8532 Email #1: [EMAIL PROTECTED] Email #2: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: dynamic node selection
Adam there's no "dynamic" xpath expression evaluation in XSLT - you'll probably want to find some other way to identify the nodes you want to deal with since writing a generic xpath evaluator in XSLT is not going to be easy. It would be feasible though to parse some standard type of expressions rather than any arbitrary xpath. e.g. if you could ensure that all the xpaths were like: "foo[1]/blah[2]" - but this may not be feasible since you say you don't know the possible values that your xpath expression may have? Where do they come from? Con > -Original Message- > From: Adam Flegman [mailto:[EMAIL PROTECTED] > Sent: Thursday, 24 July 2003 12:18 p.m. > To: [EMAIL PROTECTED] > Subject: Re: dynamic node selection > > > > Well, if you have your xpath in $targetnode, wouldn't it simply be: > > > > ? > > > > or > > > > > > > > > > > > To go along with your code. I haven't done XSLT in a > while, so I'm a > > little rusty. > > > Hi Tony, > > The value of $targetNode is some arbitrary string value that > (hopefully) looks > like an xml node path. At design time I dont know all the > possible values that > the $targetNode string may have. > > I have tried to use the > approach but it > seems that the 'select' part doesnt like using a string > parameter. I get the > following error report from cocoon: > > > Exception in creating Transform Handler > > More precisely: > > org.apache.cocoon.ProcessingException: Exception in creating > Transform Handler: > java.lang.NullPointerException > > > > If I could find a way to take the string value of $targetNode > and actually > select the corresponding nodes then I think the problem is solved. > > > Ad. > > = > Adam Flegman - Senior Software Engineer > > Mobile: (0414) 375 735 > Phone: (07) 5547 8530 > Facsimile: (07) 5547 8532 > Email #1: [EMAIL PROTECTED] > Email #2: [EMAIL PROTECTED] > > __ > Do you Yahoo!? > Yahoo! SiteBuilder - Free, easy-to-use web site design software > http://sitebuilder.yahoo.com > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamic node selection
> Well, if you have your xpath in $targetnode, wouldn't it simply be: > > ? > > or > > > > > > To go along with your code. I haven't done XSLT in a while, so I'm a > little rusty. > Hi Tony, The value of $targetNode is some arbitrary string value that (hopefully) looks like an xml node path. At design time I dont know all the possible values that the $targetNode string may have. I have tried to use the approach but it seems that the 'select' part doesnt like using a string parameter. I get the following error report from cocoon: Exception in creating Transform Handler More precisely: org.apache.cocoon.ProcessingException: Exception in creating Transform Handler: java.lang.NullPointerException If I could find a way to take the string value of $targetNode and actually select the corresponding nodes then I think the problem is solved. Ad. = Adam Flegman - Senior Software Engineer Mobile: (0414) 375 735 Phone: (07) 5547 8530 Facsimile: (07) 5547 8532 Email #1: [EMAIL PROTECTED] Email #2: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamic node selection
Adam Flegman wrote: For example if parameters parentNode = "foo" and childNode = "bar", then $targetNode would evaluate to the string "foo/bar". I would want the 'for-each' statement to select all the "bar" nodes under the "foo" parent node. I think the only step I am missing is how to write a xpath node selection query that can take a string parameter as its argument. Well, if you have your xpath in $targetnode, wouldn't it simply be: ? or To go along with your code. I haven't done XSLT in a while, so I'm a little rusty. Tony - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamic node selection
Hi Tony, > > > > > > > > > >>name="targetNode" > >select="concat(name($listNode),'/',$listItem)" /> > > > > > > > > ... do the processing > > > > > > > >Any advice, greatly appreciated. > > > > > > > > Adam, > > I'm not too sure what you're trying to do. Are you trying to create an > element named with the value of $targetNode? Or are you trying to apply > your templates to the nodes named in the value of $targetNode? > > If all you're trying to do is create a new named $targetNode, all you'd > have to do is: > > foo > > So, again, I'm not to sure what you're trying to accomplish.. perhaps an > xslt list can help. > > Tony > My apologies for the lack of clarity. I was trying to use the value I have calcualted for the $targetNode variable to select a node in my XML document. If I had an xml source like the following, I would like to be able to 'dynamically' select nodes for processing. The xslt template to do the processing: ... do the processing For example if parameters parentNode = "foo" and childNode = "bar", then $targetNode would evaluate to the string "foo/bar". I would want the 'for-each' statement to select all the "bar" nodes under the "foo" parent node. I think the only step I am missing is how to write a xpath node selection query that can take a string parameter as its argument. Thanks for your time Tony. Ad. = Adam Flegman - Senior Software Engineer Mobile: (0414) 375 735 Phone: (07) 5547 8530 Facsimile: (07) 5547 8532 Email #1: [EMAIL PROTECTED] Email #2: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamic node selection
Adam Flegman wrote: Hi Guys, I have been trying to re-factor some existing xslt code and wonder if it is possible to select nodes based on a string. The string is built up by parameters so the value of the target node is determined each time the xsl template is called. I am having trouble using the string to select the target node. In the sample below I can calculate the name of the target node I am after, but I am unsure how to convert the name into an actual node. ... do the processing Any advice, greatly appreciated. Adam, I'm not too sure what you're trying to do. Are you trying to create an element named with the value of $targetNode? Or are you trying to apply your templates to the nodes named in the value of $targetNode? If all you're trying to do is create a new named $targetNode, all you'd have to do is: foo So, again, I'm not to sure what you're trying to accomplish.. perhaps an xslt list can help. Tony - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]