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 7th, 2003, 06:33 PM
Registered User
 
Join Date: Nov 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to output non-well formed string

Hi,
I have the following template which is producing the output as shown.

Template: ( Suggested earlier by Sam .. in reply to my previous mail )

<xsl:template match="mml:mo[.='(']">

<xsl:variable name="moWithParen" select="count(preceding::mo[text() = '('])"/>
    <prompt><goto next = "{$moWithParen}"/></prompt>
    <prompt>&lt;/form&gt;</prompt>
    &lt;prompt&gt;
        <xsl:text disable-output-escaping="yes">&lt;form name = "{$moWithParen}"&gt;</xsl:text>
        &lt;/prompt&gt;
</xsl:template>


Output:

<form name = "{$moWithParen}">

My problem is that I am unable to print the number.. I mean the output should be

<form name = "1">

Here it should print this line whenever my xml document matches <mo>'('</mo>

It should print the line <form name = "1"> Also the number should increment so that its always distinct.

In My XSLT if I use '<' and '>' instead of &lt; and &gt; then it gives me error because <form name = "1"> is not well formed output.

Please tell me how to get the result without error.

kindly help is needed

Thank you
gs
 
Old November 7th, 2003, 07:57 PM
Authorized User
 
Join Date: Oct 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HTH and could not test this, but try:

<xsl:variable name="moWithParen" select="count(preceding::mo[text() = '('])"/>
    <prompt><goto next = "{$moWithParen}"/></prompt>
    <prompt>&lt;/form&gt;</prompt><xsl:text>
    &lt;prompt&gt;
        &lt;form name = "</xsl:text><xsl:value-of select="$moWithParen"/><xsl:text>"&gt;
        &lt;/prompt&gt;</xsl:text>
</xsl:template>

...sam

 
Old November 8th, 2003, 03:43 PM
Registered User
 
Join Date: Nov 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi sam,
By using this technique the counter doesnt get incremented as required
it displays the <form name ="0"> always.

gs

Quote:
quote:Originally posted by shbyland
 HTH and could not test this, but try:

<xsl:variable name="moWithParen" select="count(preceding::mo[text() = '('])"/>
    <prompt><goto next = "{$moWithParen}"/></prompt>
    <prompt>&lt;/form&gt;</prompt><xsl:text>
    &lt;prompt&gt;
        &lt;form name = "</xsl:text><xsl:value-of select="$moWithParen"/><xsl:text>"&gt;
        &lt;/prompt&gt;</xsl:text>
</xsl:template>

...sam

 
Old November 10th, 2003, 11:51 AM
Authorized User
 
Join Date: Oct 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

gs,

when I use the following stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html"/>

    <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:variable name="moWithParen" select="count(preceding::mo[text() = '('])"/>

        <prompt><goto next = "{$moWithParen}"/></prompt>
        <prompt><xsl:text disable-output-escaping="yes">&lt;/form&gt;</xsl:text></prompt><xsl:text disable-output-escaping="yes">
        &lt;prompt&gt;
        &lt;form name = "</xsl:text><xsl:value-of select="$moWithParen"/><xsl:text disable-output-escaping="yes">"&gt;
        &lt;/prompt&gt;</xsl:text>

    </xsl:template>

</xsl:stylesheet>

to transform the following XML:

<test>
    <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>
        <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>
</test>

I get the following output:

<test>
   <mrow>
      <mi>erf</mi>
      <mo>#8289;</mo>
      <prompt>
         <goto next="0"></goto>
      </prompt>
      <prompt></form></prompt>
              <prompt>
              <form name = "0">
              </prompt>
      <mrow>
         <mi>a</mi>
         <mo>#8290;</mo>
         <mi>z</mi>
      </mrow>
      <mo>)</mo>
   </mrow>
   <mo>#8290;</mo>
   <mrow>
      <mi>erf</mi>
      <mo>#8289;</mo>
      <prompt>
         <goto next="1"></goto>
      </prompt>
      <prompt></form></prompt>
              <prompt>
              <form name = "1">
              </prompt>
      <mrow>
         <mi>b</mi>
         <mo>#8290;</mo>
         <mi>z</mi>
      </mrow>
      <mo>)</mo>
   </mrow>
   <mrow>
      <mi>erf</mi>
      <mo>#8289;</mo>
      <prompt>
         <goto next="2"></goto>
      </prompt>
      <prompt></form></prompt>
              <prompt>
              <form name = "2">
              </prompt>
      <mrow>
         <mi>a</mi>
         <mo>#8290;</mo>
         <mi>z</mi>
      </mrow>
      <mo>)</mo>
   </mrow>
   <mo>#8290;</mo>
   <mrow>
      <mi>erf</mi>
      <mo>#8289;</mo>
      <prompt>
         <goto next="3"></goto>
      </prompt>
      <prompt></form></prompt>
              <prompt>
              <form name = "3">
              </prompt>
      <mrow>
         <mi>b</mi>
         <mo>#8290;</mo>
         <mi>z</mi>
      </mrow>
      <mo>)</mo>
   </mrow>
</test>

which looks to be incrementing fine in both places. You'll need to provide more information to debug your problem: what XSLT processor are you using? Can you provide the sample XML, XSL, and output you are getting?

...sam

 
Old November 10th, 2003, 06:30 PM
Registered User
 
Join Date: Nov 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
       I was not including the namespace while matching the mo. I had to match mml:mo. Sam its working perfectly fine now. I have one more problem regarding this .. I was just numbering whenever I matched <mo>(</mo>. But, I dont want to number the consecutive <mo>(</mo> which are just seperated by one or more <mrow> or </mrow>. How should my condition be to achieve this condition.

Kindly help is appreciated
Thank you
gs

 
Old November 10th, 2003, 11:47 PM
Authorized User
 
Join Date: Oct 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

gs,

can you give a more specific example? i.e. provide some xml that gives you the "wrong" result when you transform it with your current stylesheet, and what you need as the right result.

...sam






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to output the entire content to a string sunnyman XML 6 November 29th, 2007 10:48 PM
XML That Is Not Well Formed rvanandel Ajax 3 July 2nd, 2007 11:46 AM
The server tag is not well formed. binici ASP.NET 2.0 Basics 6 May 15th, 2007 04:41 PM
Output loop data to a string iloveoatmeal Classic ASP Basics 2 December 22nd, 2005 08:28 PM
Well formed HTML dkb XSLT 1 October 27th, 2003 01:16 PM





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