You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "Johnson, Chris" <ch...@ti.com> on 2004/03/25 19:02:51 UTC

xPath question

I know this isn't a purely taglib question, so just scream at me if I'm
out of line here...
 
Is there a way in xpath to include the immediate parent node in the
resulting node set?
 
example:
 
initial xml:
<a>
    <b>row1</b>
    <b>row2</b>
    <b>row3</b>
    <b>row4</b>
    <b>row5</b>
    <b>row6</b>
<a>
 
xpath="/a/b[position()<3]"
 
That will return me: 
<b>row1</b>
<b>row2</b>
 
But what I really want is:
<a>
    <b>row1</b>
    <b>row2</b>
</a>
 
I guess I just need to know if this is even a possibility in xpath (was
it designed to do this?).  If not, then I can stop killing myself trying
to figure out how.
 
Thanks,
 
Chris Johnson 
Texas Instruments
chrisjohnson@ti.com 
 

Re: xPath question

Posted by Kris Schneider <kr...@dotech.com>.
XSLT might be more useful here:

JSP:
----
<c:import url="/WEB-INF/test.xml" var="xml"/>
<c:import url="/WEB-INF/test.xsl" var="xslt"/>
<x:transform xml="${xml}" xslt="${xslt}"/>

/WEB-INF/test.xml:
------------------
<a>
  <b>row1</b>
  <b>row2</b>
  <b>row3</b>
  <b>row4</b>
  <b>row5</b>
  <b>row6</b>
</a>

/WEB-INF/test.xsl:
------------------
<a xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xsl:version="1.0">
  <xsl:copy-of select="//b[position() &lt; 3]"/>
</a>

Quoting "Johnson, Chris" <ch...@ti.com>:

> I know this isn't a purely taglib question, so just scream at me if I'm
> out of line here...
>  
> Is there a way in xpath to include the immediate parent node in the
> resulting node set?
>  
> example:
>  
> initial xml:
> <a>
>     <b>row1</b>
>     <b>row2</b>
>     <b>row3</b>
>     <b>row4</b>
>     <b>row5</b>
>     <b>row6</b>
> <a>
>  
> xpath="/a/b[position()<3]"
>  
> That will return me: 
> <b>row1</b>
> <b>row2</b>
>  
> But what I really want is:
> <a>
>     <b>row1</b>
>     <b>row2</b>
> </a>
>  
> I guess I just need to know if this is even a possibility in xpath (was
> it designed to do this?).  If not, then I can stop killing myself trying
> to figure out how.
>  
> Thanks,
>  
> Chris Johnson 
> Texas Instruments
> chrisjohnson@ti.com 

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org