rumkarma Posted February 16, 2011 Share Posted February 16, 2011 hi seniors ,Pls take a look at my XML: <root><library><name>lib</name><address>123 abc strt </address><books><book><title>abc</title><isbn>91-7-182-83-38</isbn></book><book><title>rty</title><isbn>91-6-183-87-21</isbn></book><bookset><title>set1</title><book><title>qri</title><isbn>91-0-172-99-45</isbn></book><book><title>agk</title><isbn>96-3-146-24-52</isbn></book><book><title>vbn</title><isbn>92-7-765-34-97</isbn></book></bookset><book><title>lkj</title><isbn>94-6-369-57-28</isbn></book><book><title>tgb</title><isbn>97-4-617-05-01</isbn></book><bookset><title>set2</title><book><title>egm</title><isbn>95-3-984-27-10</isbn></book><book><title>pjc</title><isbn>97-7-872-49-38</isbn></book></bookset><book><title>wer</title><isbn>97-6-325-26-19</isbn></book></books></library></root> The output I'm looking for is something like this: <html><head><title>books</title><body>9171828338 OR 9161838721<a href="link">set1</a>9463695728 OR 9746170501<a href="link">set2</a>9763252619</body></html> But no matter wat I do, either all the <book>ISBNs are displayed right at the top or the bottom together and the links are displayed together. But whenever i encounter a <book> i want its ISBN and if the next tag too is a <book> then i want to add the ISBN of this too and so on till i reach a <bookset> which i deal with differently. But this doesnt seem possible. Any suggestions? Link to comment Share on other sites More sharing options...
rumkarma Posted February 18, 2011 Author Share Posted February 18, 2011 hello again,i've the following XSL code: <xsl:template match="root/library"><xsl:apply-templates select="books/book|books/bookset"/></xsl:template><xsl:template match="/root/library/books/book"><xsl variable name="isbn1" select="isbn"><xsl:value-of select="translate($isbn1,'-','')"><br/></xsl:template><xsl:template match="/root/library/books/bookset"><a href="link"><xsl:value-of select="title"></a><br/></xsl:template> this gives the following output: 9171828338<br/>9161838721<br/><a href="link">set1</a><br/>9463695728<br/>9746170501<br/><a href="link">set2</a><br/>9763252619<br/> but i want the 'leaf' <book>s' occuring successively to be grouped together.(9171828338 OR9161838721<br/> shud be the first line n so on.) And any number of <book> can appear together. I tried using for-each and following-sibling but that didnt work out either.Is this even possible? Pls do help me out . Any help is much appreciated.Thanks. Link to comment Share on other sites More sharing options...
JohnBampton Posted February 22, 2011 Share Posted February 22, 2011 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="root/library"> <xsl:apply-templates select="books/book|books/bookset"/> </xsl:template> <xsl:template match="/root/library/books/book"> <xsl:value-of select="translate(isbn,'-','')"/> <xsl:choose> <xsl:when test="name(following-sibling::*[1]) = 'book'"> <xsl:text> OR </xsl:text> </xsl:when> <xsl:otherwise> <br/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="/root/library/books/bookset"> <a href="link"> <xsl:value-of select="title"/> </a> <br/> </xsl:template></xsl:stylesheet> regards, John Bampton. Link to comment Share on other sites More sharing options...
rumkarma Posted February 22, 2011 Author Share Posted February 22, 2011 Thanks a lot John.I will try it out. Very hopeful this will work. Thanks again. Link to comment Share on other sites More sharing options...
JohnBampton Posted February 22, 2011 Share Posted February 22, 2011 I just gave you the answer Link to comment Share on other sites More sharing options...
rumkarma Posted February 22, 2011 Author Share Posted February 22, 2011 I just gave you the answerYes just saw that. Link to comment Share on other sites More sharing options...
rumkarma Posted February 22, 2011 Author Share Posted February 22, 2011 John you are my saviour. Worked like a charm. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.