473,396 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

xslt - separating element and text

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
Jul 20 '05 #1
3 1314


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/
Jul 20 '05 #2
Martin Honnen <ma*******@yahoo.de> wrote in message news:<41***********************@newsread2.arcor-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'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:output 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>
Jul 20 '05 #3
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_
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
2
by: Ralf Wahner | last post by:
Dear Masters of XSLT Could I ask you for a clue on the following question? I'd like to use XSLT to transform an XML source file to LaTeX. In the following small example the <para> Element...
2
by: Martin | last post by:
Hallo, can you help me writing a generic xslt transformation (useable with xsql from oracle)? The problem is how to get the escaping characters .... === INPUT-File in.xml <?xml version =...
2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
0
by: shapper | last post by:
Hello, I am transforming a XML file into another XML file using a XSLT. Everything is working fine! I have only one problem: I want one of the values in my XSLT file to be taken from a Key...
6
by: John Larson | last post by:
Hi All, I am some information from INSPEC database records in XML to build a relational database of my own. I am currently trying to extract information by doing an XSLT transform of the XML...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.