Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 30th, 2009, 02:19 AM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 2
Thanked 1 Time in 1 Post
Send a message via Yahoo to mail4kaja
Question Get Intersect of Sequences in XPath for XSLT

Hello everyone...

I'm building a inventory kind of application where I'm building the Navigation using XSLT on my Data model. My model looks something similar to the following.

Code:
 
<MyStore>
 <Items>
  <Item itemId="1"><Name>Item One</Name>....</Item>
  <Item itemId="2"><Name>Item Name 2</Name>....</Item>
  <Item itemId="3"><Name>Item Name 3</Name>....</Item>
  <Item itemId="4"><Name>Item Four</Name>....</Item>
 </Items>
 <Categories>
   <Category catId="1">
     <Item ItemId="2"/>
     <Item ItemId="3"/>
  </Category>
   <Category catId="2">
     <Item ItemId="1"/>
     <Item ItemId="2"/>
     <Item ItemId="4"/>
  </Category>
 </Categories>
</MyStore>
I'm using backbase. I'm creating a listgrid for each category to list the items in it.

My XSLT looks likes this.

Code:
<xsl:for-each select"Categories/Category">
<!-- selecting @ItemId will give the list of ItemIds in THAT category -->
<b:listgrid>
<b:colgrid select="XPATH"/>
<!-- Here, I need to give an XPath that gives the list of ItemNames whose itemIds are present in Category -->
</b:listgrid>
</xsl:for-each>
I'm using for-each to process each category. I can get the list of ItemIds, but how to I get the XPath that gives the ItemNames of those Items.

Please help me..

Thanks in advance,

With regards,
R Kaja Mohideen
__________________
R Kaja Mohideen
http://www.vhost4all.com/

Last edited by mail4kaja; January 30th, 2009 at 03:06 AM..
 
Old January 30th, 2009, 02:38 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Your question is not clear. Please post the xslt script you are using and also post the needed output from the input xml.
__________________
Rummy
 
Old January 30th, 2009, 03:07 AM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 2
Thanked 1 Time in 1 Post
Send a message via Yahoo to mail4kaja
Default

Thanks for your comment, updated my post.
__________________
R Kaja Mohideen
http://www.vhost4all.com/
The Following User Says Thank You to mail4kaja For This Useful Post:
mrame (January 30th, 2009)
 
Old January 30th, 2009, 04:21 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Try the below:
Code:
 
<xsl:template match="MyStore">
<xsl:for-each select="Categories/Category">
<b:listgrid>
<b:colgrid>
<xsl:for-each select="Item">
<xsl:if test="@ItemId = ../../../Items/Item/@itemId">
<xsl:variable name="id" select="@ItemId"></xsl:variable>
<xsl:value-of select="../../../Items/Item[@itemId = $id]/Name"/>
</xsl:if>
</xsl:for-each>
</b:colgrid>
</b:listgrid>
</xsl:for-each>
</xsl:template>
__________________
Rummy

Last edited by mrame; January 30th, 2009 at 04:26 AM..
 
Old January 30th, 2009, 04:35 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

You can also delete the xsl:if, if its not needed at that place.
__________________
Rummy
The Following User Says Thank You to mrame For This Useful Post:
mail4kaja (January 30th, 2009)
 
Old January 30th, 2009, 04:41 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Note that technically what you are looking for is a join, not an intersection. It helps to learn the terminology as your searches for information (in google or in the index of a good old book) are likely to be more successful.

I'm afraid I don't know what "backbase" is, and I'm therefore rather unclear whether you are looking for an XSLT solution or a pure XPath solution (and if so, whether XPath 1.0 or XPath 2.0). In XSLT, a solution like that from mrame works fine. In pure XPath 1.0, joins can be difficult unless you are able to bind variables.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following 2 Users Say Thank You to mhkay For This Useful Post:
mail4kaja (January 30th, 2009), mrame (January 30th, 2009)
 
Old January 30th, 2009, 07:21 AM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 2
Thanked 1 Time in 1 Post
Send a message via Yahoo to mail4kaja
Default

Thanks mrame. But, I can't do any transform there inside colgrid. I just need a XPath that gives me the List of Item Names for that group. So that listgrid will populate its table column.

Code:
<b:colgrid select="XPATH"/>
mhkay, I think i need an XPath solution. May be in 1.0 or 2.0 ...

Please help me.

Thanks & Regards,
R Kaja Mohideen
__________________
R Kaja Mohideen
http://www.vhost4all.com/
 
Old February 2nd, 2009, 03:19 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

As already said, post the needed output xml for the posted input xml. So that it wuold be easy for us to give the exact solution.
__________________
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
JAXP and XSLT 2.0 / XPATH 2.0 ojasrege XSLT 2 November 27th, 2007 10:40 AM
xslt xpath boris17 XSLT 2 October 15th, 2007 05:31 PM
intersect operator kapy_kal XSLT 1 March 29th, 2006 02:02 PM
XSLT -XPATH Error xslspy XSLT 1 October 27th, 2005 03:24 AM
XSLT/XPATH Help KombatKarl XSLT 3 September 2nd, 2004 07:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.