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 April 25th, 2006, 12:08 AM
Authorized User
 
Join Date: Apr 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generation of numbers and subnumbers

This is my XML file
===================
<equation id="E0000023" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000024" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000025" second.level="reset" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000026" second.level="increase" increase.first="0" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000027" second.level="reset" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000028" second.level="increase" increase.first="0" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000029" second.level="increase" increase.first="0" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000030" second.level="reset" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000031" second.level="increase" increase.first="0" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000032" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000033" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

This is my XSL coding
=====================
<xsl:template match="equation">
<a><xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute></a><br/><br/><table width="100%" border="0"><tr><td width="900"><xsl:apply-templates/></td><td align="right" width="100"><xsl:variable name="eq" select="substring-after(@id,'E')"/><text>(Eq </text><xsl:value-of select="string($eq*1)"/><text>)</text></td></tr></table><br/>
</xsl:template>


<xsl:template match="equation[@second.level='reset']">
<a><xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute></a><br/><br/><table width="100%" border="0"><tr><td width="900"><xsl:apply-templates/></td><td align="right" width="100"><xsl:variable name="eq" select="substring-after(@id,'E')"/><text>(Eq </text><xsl:value-of select="string($eq*1)"/><text>
<xsl:number count="equation[(@second.level)]" format="a"/>)</text></td></tr></table><br/>
</xsl:template>

<xsl:template match="equation[@second.level='increase' and @increase.first='0']">
<a><xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute></a><br/><br/><table width="100%" border="0"><tr><td width="900"><xsl:apply-templates/></td><td align="right" width="100"><xsl:variable name="eq" select="substring-after(@id,'E')"/><text>(Eq </text><xsl:value-of select="string($eq*1)"/><text>
<xsl:number count="equation[(@second.level)]" format="a"/>)</text></td></tr></table><br/>
</xsl:template>

Currently I am getting the following output
===========================================
.
.
.
L = D + W (23) [for the attribute value E0000023 and so on]
L = D + W (24)
L = D + W (25a)
L = D + W (26b)
L = D + W (27a)
L = D + W (28b)
L = D + W (29a)
L = D + W (30b)
L = D + W (313)
L = D + W (32)
L = D + W (33)
.
.
.

But I need my output as under
=============================
.
.
.
L = D + W (18) [for the attribute value E0000023 and so on]
L = D + W (19)
L = D + W (20a)
L = D + W (20b)
L = D + W (21a)
L = D + W (21b)
L = D + W (21c)
L = D + W (22a)
L = D + W (22b)
L = D + W (23)
L = D + W (24)
.
.
.
Can anyone please help me with this.

Thanks



 
Old April 25th, 2006, 03:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure what you're asking. Do you understand why your code is producing L = D + W (23) as the initial output? You've evaluated substring-after(@id,'E'), multiplied by 1 to turn it into a number, and the answer is 23. You say you want to output 18 here rather than 23, but I can't see where the 18 is supposed to come from.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 25th, 2006, 03:42 AM
Authorized User
 
Join Date: Apr 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have slightly modified my XML coding to reduce any further confusion. My equation numbers should decrease depending on my attributes (second.level="reset" and second.level="increase") and these attributes are not there in an "equation" element, then depending on its previous "equation" element's attribute the number should decrease. Like for instance:

<equation id="E0000003" second.level="reset" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000004" second.level="increase" increase.first="0" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000005" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

I hope I am clear. Please give me the solution.

This is my XML file
===================
<equation id="E0000001" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000002" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000003" second.level="reset" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000004" second.level="increase" increase.first="0" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000005" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000006" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000007" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000008" second.level="reset" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000009" second.level="increase" increase.first="0" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000010" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000011" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000012" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000013" second.level="reset" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000014" second.level="increase" increase.first="0" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000015" second.level="increase" increase.first="0" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000016" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

<equation id="E0000017" numbered="1">
<bold>L</bold> = <bold>D</bold>&plus;<bold>W</bold></equation>

This is my XSL coding
=====================
<xsl:template match="equation">
<a><xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute></a><br/><br/><table width="100%" border="0"><tr><td width="900"><xsl:apply-templates/></td><td align="right" width="100"><xsl:variable name="eq" select="substring-after(@id,'E')"/><text>(Eq </text><xsl:value-of select="string($eq*1)"/><text>)</text></td></tr></table><br/>
</xsl:template>


<xsl:template match="equation[@second.level='reset']">
<a><xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute></a><br/><br/><table width="100%" border="0"><tr><td width="900"><xsl:apply-templates/></td><td align="right" width="100"><xsl:variable name="eq" select="substring-after(@id,'E')"/><text>(Eq </text><xsl:value-of select="string($eq*1)"/><text>
<xsl:number count="equation[(@second.level)]" format="a"/>)</text></td></tr></table><br/>
</xsl:template>

<xsl:template match="equation[@second.level='increase' and @increase.first='0']">
<a><xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute></a><br/><br/><table width="100%" border="0"><tr><td width="900"><xsl:apply-templates/></td><td align="right" width="100"><xsl:variable name="eq" select="substring-after(@id,'E')"/><text>(Eq </text><xsl:value-of select="string($eq*1)"/><text>
<xsl:number count="equation[(@second.level)]" format="a"/>)</text></td></tr></table><br/>
</xsl:template>

Currently I am getting the following output
===========================================
L = D + W (1) [for the attribute value E0000001 and so on]
L = D + W (2)
L = D + W (3a)
L = D + W (4b)
L = D + W (5)
L = D + W (6)
L = D + W (7)
L = D + W (8a)
L = D + W (9b)
L = D + W (10)
L = D + W (11)
L = D + W (12)
L = D + W (13a)
L = D + W (14b)
L = D + W (15c)
L = D + W (16)
L = D + W (17)

.
.
.

But I need my output as under
=============================
L = D + W (1) [for the attribute value E0000001 and so on]
L = D + W (2)
L = D + W (3a)
L = D + W (3b)
L = D + W (4)
L = D + W (5)
L = D + W (6)
L = D + W (7a)
L = D + W (7b)
L = D + W (8)
L = D + W (9)
L = D + W (10)
L = D + W (11a)
L = D + W (11b)
L = D + W (11c)
L = D + W (12)
L = D + W (13)
.
.
.


Thanks again


 
Old April 25th, 2006, 03:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Don't expect a complete solution to this for free - it's the kind of thing I do for consultancy clients.

It looks like a problem that requires use of recursive templates. You probably need to do some serious reading before you are equipped to tackle it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 25th, 2006, 04:09 AM
Authorized User
 
Join Date: Apr 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Reply me with quote

 
Old April 25th, 2006, 01:59 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Could you contact me offlist please?

mike (at) saxonica.com

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Number Generation i_shahid C# 2005 2 March 31st, 2008 10:50 PM
Report Generation kotaiah Excel VBA 0 September 14th, 2006 08:26 AM
Label generation lily611 General .NET 8 June 6th, 2005 03:19 AM
Report generation question pankaj_daga Access 5 December 21st, 2003 06:23 AM





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