XSL problem: preserve HTML tags?

XSL problem: preserve HTML tags?

Post by David Ra » Wed, 22 Mar 2000 04:00:00



I have a problem that someone may have seen before. I have an XML
document that for the sake of discussion is:

<me>
<name>Dave</name>
<mood>I am <b>happy</b>.</mood>
</me>

I want to perform an XSL transformation for <mood>, but preserve all the
HTML formatting tags between the tags referenced in the XSL statement.
For example, I can use the following XSL:

<xsl:template match="me">
<xsl: value-of select="mood"/>
</xsl:template>

Which produces:

I am happy.

What I'm looking for is an XSL command that will produce:

I am <b> happy</b>.

Any suggestions?

-Dave

 
 
 

XSL problem: preserve HTML tags?

Post by David Carlisl » Thu, 23 Mar 2000 04:00:00


Quote:} <xsl: value-of

presumably you had xsl:value-of that gives the string value of the node
If you want element nodes to be copied, you don't want the string value,
you want a copy of the node
<xsl:copy-of

David
(xsl-list is probably better than c.t.xml for xsl questions)

 
 
 

XSL problem: preserve HTML tags?

Post by Michel Hendrikse » Thu, 23 Mar 2000 04:00:00


You could match the html tags (if there are not too many..)
    ...
    <xsl:apply-templates select="mood"
    ...

<xsl:template match="mood">
    <xsl:apply-templates select="*"/>
</xsl:template>

<xsl:template match="text()">
    <xsl:value-of/>
</xsl:template>

<xsl:template match="b|B">
    <xsl:element name="B">
        <xsl:value-of/>
    </xsl:element>
</xsl:template>

Michel

for xsl questions microsoft.public.xsl...


> I have a problem that someone may have seen before. I have an XML
> document that for the sake of discussion is:

> <me>
> <name>Dave</name>
> <mood>I am <b>happy</b>.</mood>
> </me>

> I want to perform an XSL transformation for <mood>, but preserve all the
> HTML formatting tags between the tags referenced in the XSL statement.
> For example, I can use the following XSL:

> <xsl:template match="me">
> <xsl: value-of select="mood"/>
> </xsl:template>

> Which produces:

> I am happy.

> What I'm looking for is an XSL command that will produce:

> I am <b> happy</b>.

> Any suggestions?

> -Dave


 
 
 

XSL problem: preserve HTML tags?

Post by Vitaly Lipovetsk » Thu, 23 Mar 2000 04:00:00


Is there any stanadard to write XML files.
I mean something like DOM or SAX but for writing.

--
My best regards,
Vitaly Lipovetsky.
Deputy head of IT division
First Ukrainian Intl bank

Brainbench(Tekmetrix) e-certification id 14050 SYBASE DBA 4.38
Brainbench(Tekmetrix) e-certification id 14050 MS SQL Server DBA 4.51

 
 
 

XSL problem: preserve HTML tags?

Post by hell.. » Thu, 23 Mar 2000 04:00:00


Why the sax parsing stop as soon as it finds the
first endElement ?

The parser goes to endDocument() as soon as it
finds the first endElement (like </stuff> ) in my
xml file.....

Is there somenone who knows where my error can
be ?

Thanks

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

XSL problem: preserve HTML tags?

Post by mhell.. » Thu, 23 Mar 2000 04:00:00


Why the sax parsing stop as soon as it finds the first endElement ?

The parser goes to endDocument() as soon as it finds the first
endElement (like </stuff> ) in my xml file.....

Is there somenone who knows where my error can be ?

Thanks

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

XSL problem: preserve HTML tags?

Post by mhell.. » Thu, 23 Mar 2000 04:00:00


Why the sax parsing stop as soon as it finds the first endElement ?

The parser goes to endDocument() as soon as it finds the first
endElement (like </stuff> ) in my xml file.....

Is there somenone who knows where my error can be ?

Thanks

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

XSL problem: preserve HTML tags?

Post by Howard Kat » Thu, 23 Mar 2000 04:00:00


Hard to know without seeing your data. Can we see your file?

Howard

Howard


> Why the sax parsing stop as soon as it finds the first endElement ?

> The parser goes to endDocument() as soon as it finds the first
> endElement (like </stuff> ) in my xml file.....

> Is there somenone who knows where my error can be ?

> Thanks

> Sent via Deja.com http://www.deja.com/
> Before you buy.

 
 
 

XSL problem: preserve HTML tags?

Post by mhell.. » Fri, 24 Mar 2000 04:00:00


In fact, with this exemple, the parser doesn't work :

********** MyHandler.java ************

import org.xml.sax.HandlerBase;
import org.xml.sax.AttributeList;

public class MyHandler extends org.xml.sax.HandlerBase {

public MyHandler() {
        super();

Quote:}

  public void endElement (String name)
  {
        System.out.println("End element: " + name);
  }
  public void startElement (String name, AttributeList atts)
  {
        System.out.println("Start element: " + name);
  }

Quote:}

*********** SAXApp.java ************

import org.xml.sax.Parser;
import org.xml.sax.DocumentHandler;
import org.xml.sax.helpers.ParserFactory;

public class SAXApp {

        static final String parserClass =
"com.ibm.xml.parser.SAXDriver";

  public static void main (String args[])
        throws Exception
  {
        Parser parser = ParserFactory.makeParser(parserClass);
        DocumentHandler handler = new MyHandler();
        parser.setDocumentHandler(handler);

          parser.parse("test.xml");

  }

Quote:}

********* test.xml ***********

<?xml version="1.0" ?>
<message>
        <date>2000-03-20</date>
        <expediteur>martin</expediteur>
</message>

*********** and the answer is ********

Start element : message
Start element : date
End element : date

************* The problem ***********

Why the sax parsing stop as soon as it finds the first endElement ?

The parser doesn't parse all my xml file, and I don't know why...

Thanks for your answer, Marc.



> Hard to know without seeing your data. Can we see your file?

> Howard

> Howard


> > Why the sax parsing stop as soon as it finds the first endElement ?

> > The parser goes to endDocument() as soon as it finds the first
> > endElement (like </stuff> ) in my xml file.....

> > Is there somenone who knows where my error can be ?

> > Thanks

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.
 
 
 

XSL problem: preserve HTML tags?

Post by Howard Kat » Fri, 24 Mar 2000 04:00:00


I don't see anything obviously wrong with your data or your code. I ran
your file just fine under Sun's parser, using very similar code.

Is there any possibility you're throwing an exception once you get past
the </date> tag and you're not reporting it? I wonder about the
possibility of illegal characters in your file. Any accent marks on
expediteur? You're not declaring the encoding as "ISO-8859-1", so the
parser might be complaining strenuously if it is finding accented
characters.

Other than that ... ?

Howard


> In fact, with this exemple, the parser doesn't work :

> ********** MyHandler.java ************

> import org.xml.sax.HandlerBase;
> import org.xml.sax.AttributeList;

> public class MyHandler extends org.xml.sax.HandlerBase {

> public MyHandler() {
>         super();
> }
>   public void endElement (String name)
>   {
>         System.out.println("End element: " + name);
>   }
>   public void startElement (String name, AttributeList atts)
>   {
>         System.out.println("Start element: " + name);
>   }
> }

> *********** SAXApp.java ************

> import org.xml.sax.Parser;
> import org.xml.sax.DocumentHandler;
> import org.xml.sax.helpers.ParserFactory;

> public class SAXApp {

>         static final String parserClass =
> "com.ibm.xml.parser.SAXDriver";

>   public static void main (String args[])
>         throws Exception
>   {
>         Parser parser = ParserFactory.makeParser(parserClass);
>         DocumentHandler handler = new MyHandler();
>         parser.setDocumentHandler(handler);

>           parser.parse("test.xml");

>   }
> }

> ********* test.xml ***********

> <?xml version="1.0" ?>
> <message>
>         <date>2000-03-20</date>
>         <expediteur>martin</expediteur>
> </message>

> *********** and the answer is ********

> Start element : message
> Start element : date
> End element : date

> ************* The problem ***********

> Why the sax parsing stop as soon as it finds the first endElement ?

> The parser doesn't parse all my xml file, and I don't know why...

> Thanks for your answer, Marc.



> > Hard to know without seeing your data. Can we see your file?

> > Howard

> > Howard


> > > Why the sax parsing stop as soon as it finds the first endElement ?

> > > The parser goes to endDocument() as soon as it finds the first
> > > endElement (like </stuff> ) in my xml file.....

> > > Is there somenone who knows where my error can be ?

> > > Thanks

> > > Sent via Deja.com http://www.deja.com/
> > > Before you buy.

> Sent via Deja.com http://www.deja.com/
> Before you buy.

 
 
 

XSL problem: preserve HTML tags?

Post by yclept Keshl » Sat, 25 Mar 2000 04:00:00



> Is there any stanadard to write XML files.
> I mean something like DOM or SAX but for writing.

Yes: DOM or SAX. Build a DOM tree and pass it to code that
will generate XML syntax from its contents. DOM Level 3 will
provide a standardized API for writing out the contents of a
DOM; until that's ready, you can use one of the many
off-the-shelf routines that perform this function.

Or implement the parser side of SAX in your own code and
generate a series of event calls to a SAX listener which
generates XML syntax. Again, there are many off-the-shelf
implementations available.

If you're using the IBM/Apache parser, see the DOMWriter and
SAXWriter sample programs that come with it.

--
-----------------------------------------------------------------

 
 
 

1. preserving line breaks and HTML tags in XSLT

I've got an XSLT which will preserve line breaks in the output HTML so the
user doesn't have to specify <br> or <p> to keep paragraphs and line breaks.

The problem is I want to be able to put <b> / <i> tags straight into the
text of the document and have them preserved when it is transformed into
HTML.

I've tried <xsl:copy> and <xsl:copy-of> but when the text is then put
through the <xsl:template> which preserves the line breaks the HTML tags are
stripped out.

Does anyone know how to preserve the HTML tags and preserve the line breaks?

I am using ASP with MSXML

all help appreciated,

Paul
--
http://www25.brinkster.com/dazzle
Make a donation to Open Source support and development:
http://www.25.brinkster.com/dazzle#donations
The Jesus Christ Cafe - an ebook not a religion -
http://www.nospine.net/default.asp?ShowTitle=0044-00194-001

2. cross-over problem with SMC 8216 cards

3. Preserving space around inline HTML tags?

4. Dell Axim X5 for $259

5. preserving line breaks and HTML tags in text

6. How to pass a Reference to an Iunknown

7. HTML tag in a xsl:if without end tag and using xsl:attribute

8. New Atari Binaries Group

9. how to embed xsl tag within an html tag

10. XSL tag into HTML tag

11. xml to html using xsl: How to preserve xml encoding ?

12. preserve entities (after XSL->HTML transformation)

13. How can I preserve HTML using XSL?