Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xslt - separating element and text

Reply
Thread Tools

xslt - separating element and text

 
 
Jijai
Guest
Posts: n/a
 
      09-18-2004
Hi All,

I need your help. I have spent almost one day to figure this out, here
is my problem:

In my dtd:

<!ELEMENT para (#PCDATA | math | link)+>

In my xml:

<para>
sentence1
<math>math equation</math>
sentence2
<link href="somewhere">link</link>
sentence3
</para>

I want to transform my xml into html by using an xsl, and i want to
change every <link> in <para> value there into <a href=".."> form. And
i also want to copy everything inside <math> into my html page. Is
there any solution for this?
Thanks in advance for your help.

regards,
Jijai
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      09-18-2004


Jijai wrote:


> I need your help. I have spent almost one day to figure this out, here
> is my problem:
>
> In my dtd:
>
> <!ELEMENT para (#PCDATA | math | link)+>
>
> In my xml:
>
> <para>
> sentence1
> <math>math equation</math>
> sentence2
> <link href="somewhere">link</link>
> sentence3
> </para>
>
> I want to transform my xml into html by using an xsl, and i want to
> change every <link> in <para> value there into <a href=".."> form. And
> i also want to copy everything inside <math> into my html page. Is
> there any solution for this?


You haven't shown us what HTML output you want so I can only guess:

<xsl:template match="para">
<p>
<xsl:apply-templates />
</p>
</xsl:template>

<xsl:template match="link">
<a href="{@href}"><xsl:value-of select="." /></a>
</xsl:template>

<xsl:template match="math">
<xsl:apply-templates />
</xsl:template>


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Jijai
Guest
Posts: n/a
 
      09-18-2004
Martin Honnen <(E-Mail Removed)> wrote in message news:<414c5017$0$18550$(E-Mail Removed)-online.net>...
> Jijai wrote:
>
>
> > I need your help. I have spent almost one day to figure this out, here
> > is my problem:
> >
> > In my dtd:
> >
> > <!ELEMENT para (#PCDATA | math | link)+>
> >
> > In my xml:
> >
> > <para>
> > sentence1
> > <math>math equation</math>
> > sentence2
> > <link href="somewhere">link</link>
> > sentence3
> > </para>
> >
> > I want to transform my xml into html by using an xsl, and i want to
> > change every <link> in <para> value there into <a href=".."> form. And
> > i also want to copy everything inside <math> into my html page. Is
> > there any solution for this?

>
> You haven't shown us what HTML output you want so I can only guess:
>
> <xsl:template match="para">
> <p>
> <xsl:apply-templates />
> </p>
> </xsl:template>
>
> <xsl:template match="link">
> <a href="{@href}"><xsl:value-of select="." /></a>
> </xsl:template>
>
> <xsl:template match="math">
> <xsl:apply-templates />
> </xsl:template>


Oops, sorry, forgot to give the output, here is the output that i
want:

<p>
sentence1 <math>...</math> sentence2 <a href="..">link</a> sentence3
</p>

Anyway, i already tried your suggestion but the <math> tag is not
included in the output, i made a modification and it works thanks
man.

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

<xslutput method="html"/>
<xsl:template match="doc">
<p>
<xsl:apply-templates />
</p>
</xsl:template>

<xsl:template match="link">
<a href="{@href}"><xsl:value-of select="." /></a>
</xsl:template>

<xsl:template match="math">
<xsl:apply-templates select="." mode="math-ns-copy"/>
</xsl:template>

<xsl:template match="*" mode="math-ns-copy">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="math-ns-copy"/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      09-22-2004
Jijai wrote:
[...]
> <xsl:template match="*" mode="math-ns-copy">
> <xsl:element name="{local-name()}">
> <xsl:copy-of select="@*"/>
> <xsl:apply-templates mode="math-ns-copy"/>
> </xsl:element>
> </xsl:template>


What's wrong with using this instead?

<xsl:template match="math">
<math>
<xsl:apply-templates/>
</math>
</xsl:template>

Entia non sunt multiplicanda præter necessitatem.

///Peter
--
"The cat in the box is both a wave and a particle"
-- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text file reading and separating words Pali C++ 10 11-08-2010 07:36 PM
WPF - separating the checkbox from text tshad ASP .Net 2 06-19-2009 05:56 PM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
separating attribution, quoted text, and sigs from the body of a post Art Merkel Perl Misc 4 02-06-2007 07:05 PM
Separating elements from a list according to preceding element Rob Cowie Python 14 03-06-2006 11:13 AM



Advertisments