Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 30th, 2009, 02:19 AM
Authorized User
 
Join Date: Nov 2008
Location: Chennai, Tamil Nadu, India.
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..
Reply With Quote
  #2 (permalink)  
Old January 30th, 2009, 02:38 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
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
Reply With Quote
  #3 (permalink)  
Old January 30th, 2009, 03:07 AM
Authorized User
 
Join Date: Nov 2008
Location: Chennai, Tamil Nadu, India.
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/
Reply With Quote
The Following User Says Thank You to mail4kaja For This Useful Post:
mrame (January 30th, 2009)
  #4 (permalink)  
Old January 30th, 2009, 04:21 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
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..
Reply With Quote
  #5 (permalink)  
Old January 30th, 2009, 04:35 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
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
Reply With Quote
The Following User Says Thank You to mrame For This Useful Post:
mail4kaja (January 30th, 2009)
  #6 (permalink)  
Old January 30th, 2009, 04:41 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
The Following 2 Users Say Thank You to mhkay For This Useful Post:
mail4kaja (January 30th, 2009), mrame (January 30th, 2009)
  #7 (permalink)  
Old January 30th, 2009, 07:21 AM
Authorized User
 
Join Date: Nov 2008
Location: Chennai, Tamil Nadu, India.
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/
Reply With Quote
  #8 (permalink)  
Old February 2nd, 2009, 03:19 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:37 PM.


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