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 November 5th, 2003, 02:36 PM
Registered User
 
Join Date: Nov 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default numbering problem

Hi all,

I need to number each occurence of '(' and ')' so that the number is distinct each time. Also the braces can be nested.
The example is used to explains the problem.
Sample XML
----------
      <mrow>
       <mi>erf</mi>
       <mo>#8289;</mo>
       <mo>(</mo>
       <mrow>
        <mi>a</mi>
        <mo>#8290;</mo>
        <mi>z</mi>
       </mrow>
       <mo>)</mo>
      </mrow>
      <mo>#8290;</mo>
      <mrow>
       <mi>erf</mi>
       <mo>#8289;</mo>
       <mo>(</mo>
       <mrow>
        <mi>b</mi>
        <mo>#8290;</mo>
        <mi>z</mi>
       </mrow>
       <mo>)</mo>
       </mrow>
      </mrow>

In this <mo>(</mo> and <mo>)</mo> can occur anywhere in the document, So starting from the first occurence i need to number whenever i come accross them correspondingly.
 when I get <mo>(<mo> my output should be
 <goto next = "XX"/>
 <form number = "XX">

where XX is distinct number whenever i come accross <mo>(</mo> in the document.
Similarly when i get <mo>)</mo> In the document I should output
  <goto next = "YY"/>
  <form number = "YY">

except for the last occurence of <mo>)</mo> where I have to just output <goto next = "end"/>

where YY is some disctinct number.

Note :-
1)XX is not equal to YY and in the whole document each occurence of
  XX and YY should be distinct.
2)Since the above is a MathML document for every ')' there will be
  corresponding '('.

 Kindly help is needed.
 Thank you.
 gs


 
Old November 5th, 2003, 03:31 PM
Authorized User
 
Join Date: Oct 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The following stylesheet copies everything to the output except the mo element when it contains either "(" or ")", at which point it outputs the "goto" or "form" elements as you asked, starting at 0 and incrementing from there. Hope it helps...

...sam

<xsl:template match="*" priority=".1">

    <xsl:copy>
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
    </xsl:copy>

</xsl:template>

<xsl:template match="mo" priority="1">

    <xsl:choose>
        <xsl:when test="text() = '(' or text() = ')'">

            <xsl:variable name="moWithParen" select="count(preceding::mo[text() = '(' or text() = ')'])"/>

            <xsl:choose>
                <xsl:when test="text() = ')' and not(following::mo[text() = ')'])">

                    <goto next = "end"/>

                </xsl:when>
                <xsl:otherwise>

                    <goto next = "{$moWithParen}"/>
                    <form number = "{$moWithParen}"/>

                </xsl:otherwise>
            </xsl:choose>

        </xsl:when>
        <xsl:otherwise>

            <xsl:copy>
                <xsl:copy-of select="@*"/>
                <xsl:apply-templates/>
            </xsl:copy>

        </xsl:otherwise>
    </xsl:choose>

</xsl:template>








Similar Threads
Thread Thread Starter Forum Replies Last Post
Numbering - For each Navy1991_1 XSLT 3 July 2nd, 2008 07:56 AM
Numbering in XSLT Angel1221 XSLT 1 June 10th, 2008 05:07 PM
Numbering problem EstherMStrom XSLT 0 January 21st, 2005 03:21 PM
Recordset numbering drumph Classic ASP Components 3 May 20th, 2004 06:54 PM
numbering harag XSLT 2 November 6th, 2003 06:04 AM





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