Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
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 September 22nd, 2009, 02:32 AM
Registered User
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to add a line number/Row number- need to use it for page breaks

Is it possible to achieve this output from the xml below:

grankids son
row 1 1 2
row:2 daughter:3
row:3 daughterinlaw:1
row:4 father:James
row:5 age:4
row:6 child:a
row:7 dog:bulldog

I need the line numbers after the row even if matching different element as above.Can this be done?Thanks in Advance


<family>
<father>
<name>James</name>
<age>4</age>
<child>
<name>a</name>
</child>
<child>
<name>b</name>
</child>
<dog>
bulldog
</dog>
</father>
<granny>
<gandkids>2</gandkids>
<son>1</son>
<daughterinlaw>1</daughterinlaw>
</granny>
</family>
Reply With Quote
  #2 (permalink)  
Old September 22nd, 2009, 04:55 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

Sorry, I don't understand how the output is related to the input. Where does "daughter:3" come from, for example? Why is child a in the output and not child b? What determines the order of the rows?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #3 (permalink)  
Old September 22nd, 2009, 08:23 AM
Registered User
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry Michael the xml didn't explain itself well enough.
I have pasted a new one below:

How can i output the below xml to html using XSL:
I need this output:- See XML below

Col1 Col2 Col3 Col4 Col5 Col6 Col7
row1:- qty product unit-price discount line-amt-ex-gst line-gst-amt
row2:stock-description
row3:stock-desc1
row5:stock-desc2
row6:- plan-code
row7:plan-desc
row8:-bundled-product
row9:bundled-desc

What i really need is to add an increment number to each row.
I can't get the position() to do this as it outputs the number based on when i match a new element e.g for the plan element i get
1
2
3
and then the outright element
1
2
3
4
etc..
what i need is
1
2
3
4
5
6
7
8 etc...

The HTML output is for printing and i need to do a page break
so i can do
<xsl:if test position() mod 2 =0>
I do a page break here <page break always>
</xsl:if>

XML below:
----------------------------------
<detail>
<plan>
<plan-code>CWTM0029BUCL30 </plan-code>
<plan-desc> Plan </plan-desc>
<ban-text>Ban :</ban-text>
<ban>40000602884 </ban>
<prorata-monthly-text>Approx pro-rata charge </prorata-monthly-text>
<prorata-call-text>Approx pro-rata included call </prorata-call-text>
<prorata-comment-1>A</prorata-comment-1>
<prorata-comment-2>B</prorata-comment-2>
<prorata-comment-3>C</prorata-comment-3>
<handset-code>NOKE63STBL </handset-code>
<handset-desc>Nokia </handset-desc>
<handset-serial>359319 </handset-serial>
<bundles>
<bundled-product>EXTENDWARR </bundled-product>
<bundled-desc>EWDIG2G </bundled-desc>
<plan-ew-imei>EW IMEI </plan-ew-imei>
<plan-ew-mobile>EW Mobile No : </plan-ew-mobile>
<plan-ew-expiry>EW Expiry Date </plan-ew-expiry>
</bundles>
<connection-type> Upgrade </connection-type>
<mobile-text>Mobile :</mobile-text>
<mobile>0666666</mobile>
<plan-cont-inc-gst> 0.00</plan-cont-inc-gst>
</plan>
<outright>
<qty>111111</qty>
<product>CJPOWERSD2GB </product>
<stock-description>Power SD2</stock-description>
<stock-desc1>Aftermarket</stock-desc1>
<stock-desc2>2GB</stock-desc2>
<unit-price>16.95</unit-price>
<discount>15.41</discount>
<line-amt-ex-gst>0</line-amt-ex-gst>
<line-gst-amt>0</line-gst-amt>
<line-amt-inc-gst>0</line-amt-inc-gst>
<item-cost>9</item-cost>
<line-cost>9</line-cost>
<gp>-9</gp>
</outright>
<ordernotes>
</ordernotes>
</detail>

Thanks in Advance and hope you understand my issue
Reply With Quote
  #4 (permalink)  
Old September 22nd, 2009, 09:53 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

I still can't easily see the logic that relates the input to the output.

But there are basically three approaches:

(a) calculate the row number as a function of things in the input document (e.g. the number of preceding siblings of the context node, etc)

(b) maintain the row number by using recursion: have a template that outputs a row and then calls the template/function to output the next row, passing the row number as a parameter

(c) use two passes, one to generate the table and the next to number the rows.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #5 (permalink)  
Old September 22nd, 2009, 09:42 PM
Registered User
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael if you look at xml input properly e.g the outright element
what i want is to make the node tags stock-description,stock-desc1 and stock-desc2 into seperate rows.
Maybe thats why you think its not logical.

How can i
(a) calculate the row number as a function of things in the input document (e.g. the number of preceding siblings of the context node, etc)

Thanks for the approaches but i would be glad if you can give me some samples or soem resources at least.
Thanks





Quote:
Originally Posted by mhkay View Post
I still can't easily see the logic that relates the input to the output.

But there are basically three approaches:

(a) calculate the row number as a function of things in the input document (e.g. the number of preceding siblings of the context node, etc)

(b) maintain the row number by using recursion: have a template that outputs a row and then calls the template/function to output the next row, passing the row number as a parameter

(c) use two passes, one to generate the table and the next to number the rows.
Reply With Quote
  #6 (permalink)  
Old September 23rd, 2009, 04:01 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

You're not explaining yourself at all well.

Is plan-code always going to be on row 6? If so, the problem is trivial: just output the number 6 when you process plan-code. So I guess it's not that simple. But if it isn't, then you need to explain where the complexity comes.

You're asking me to write code for you. I don't normally do that - I prefer to explain general principles and let you write the code, that way you learn more. But I certainly don't start writing code without a much clearer requirements statement than you have provided.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #7 (permalink)  
Old September 24th, 2009, 09:42 PM
Registered User
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry my explaination wasn't good enough let me try again.
Maybe i couldn't have used the row1,row2 etc..

Why i'm transforming this xml to HTML is for printing.
And to print i need to do a page break after for example 10 pages each.(Which means i need test for the index using position() and then apply a page break.
But unfortunately the xml i pasted earlier is not quite straight forward to transform.

The output i'm after is like so below:

Position 1 111111 CJPOWERSD2GB 16.95 15.41 0 0 0
Position 2 Power SD2
Position 3 Aftermarket
Position 4 Power SD2
Position 5 2GB
Position 6 CWTM0029BUCL30
Position 7 Plan
Position 8 Ban:
Position 9 40000602884
Position 10 EXTENDWARR
Position 11 EWDIG2G

Looking at the above you can see the output is line by line i just used the position 1,position 2 to show you what i'm after as thats what i'll be using to do a page break.
Hope you do understand now. As you said i just need you to advice me on the best approach on this.
Thanks


Quote:
Originally Posted by mhkay View Post
You're not explaining yourself at all well.

Is plan-code always going to be on row 6? If so, the problem is trivial: just output the number 6 when you process plan-code. So I guess it's not that simple. But if it isn't, then you need to explain where the complexity comes.

You're asking me to write code for you. I don't normally do that - I prefer to explain general principles and let you write the code, that way you learn more. But I certainly don't start writing code without a much clearer requirements statement than you have provided.
Reply With Quote
  #8 (permalink)  
Old September 27th, 2009, 09:42 PM
Registered User
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael any ideas on this.
Or its not possible to achieve what i posted.
No luck so far from my end.
If you have any ideas let me know.
Thanks



Quote:
Originally Posted by naijacoder View Post
Sorry my explaination wasn't good enough let me try again.
Maybe i couldn't have used the row1,row2 etc..

Why i'm transforming this xml to HTML is for printing.
And to print i need to do a page break after for example 10 pages each.(Which means i need test for the index using position() and then apply a page break.
But unfortunately the xml i pasted earlier is not quite straight forward to transform.

The output i'm after is like so below:

Position 1 111111 CJPOWERSD2GB 16.95 15.41 0 0 0
Position 2 Power SD2
Position 3 Aftermarket
Position 4 Power SD2
Position 5 2GB
Position 6 CWTM0029BUCL30
Position 7 Plan
Position 8 Ban:
Position 9 40000602884
Position 10 EXTENDWARR
Position 11 EWDIG2G

Looking at the above you can see the output is line by line i just used the position 1,position 2 to show you what i'm after as thats what i'll be using to do a page break.
Hope you do understand now. As you said i just need you to advice me on the best approach on this.
Thanks
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
Find line number of text JohnBampton XSLT 8 August 17th, 2009 09:20 AM
Issue using "saxon:line-number()" in command line XSL with Saxon9.jar ROCXY XSLT 3 June 3rd, 2009 04:24 AM
Removing unknowm number of breaks from string mat41 Classic ASP Basics 3 October 15th, 2008 08:18 PM
How to find line number FileFound Visual Studio 2005 2 June 15th, 2007 05:19 AM
To retrieve a row by giving row number prad_a MySQL 1 March 22nd, 2007 11:20 PM



All times are GMT -4. The time now is 02:20 AM.


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