New to XML - to use urls and img tags in xml?

F

Frank Stallone

I'm working on a basic css/html/xml template for my websites. I have
as much design stuff as I can put into the CSS file.

I want all my data in the xml file so my html file is, for the most
part, pulling the data from the CSS and XML file to create a page.

I'm very new to XML and google hasn't really turned up anything
useful.

Ideally what I want to do is have the code in the html to link a
datafield in the xml file - like this

<span datasrc="#xmltext" datafld="article"></span>

Then in my xml file I would want something like

<file>
<article>
blajhfierewr e9rue 9fjfidsfjdsifs <a
href="http://www.fake.com">fake</a> blah blah blah <img
src="http://www.picture.com/wang.jpg" /> blkjfriue-r blah blah, etc,
etc
</article>

Is this even possible? If a use for XML is to keep data seperate from
the html then surely there has to be a way to include links to sites
and images as most written articles have them.

Thanks in advance.
 
F

Frank Stallone

Thanks.

I had avoided XSLT because that was just something else to learn and
would delay me and I assumed since the code I was using was from
W3schools that it should be compatible across the board but I guess
not and I'll have to do it the proper way.
 
P

Peter Flynn

Frank said:
I'm working on a basic css/html/xml template for my websites. I have
as much design stuff as I can put into the CSS file.

OK so far.
I want all my data in the xml file so my html file is, for the most
part, pulling the data from the CSS and XML file to create a page.

This is where it starts to fall apart. "Pulling" XML data from within
an HTML file is a non-standard bodge.
I'm very new to XML and google hasn't really turned up anything
useful.

Not surprising, I'm afraid. Did you manage to find the FAQ at
http://www.ucc.ie/xml ?
Ideally what I want to do is have the code in the html to link a
datafield in the xml file - like this

<span datasrc="#xmltext" datafld="article"></span>

The number of browsers that this works in is probably rather limiting.
Then in my xml file I would want something like

<file>
<article>
blajhfierewr e9rue 9fjfidsfjdsifs <a
href="http://www.fake.com">fake</a> blah blah blah <img
src="http://www.picture.com/wang.jpg" /> blkjfriue-r blah blah, etc,
etc
</article>

Is this even possible? If a use for XML is to keep data seperate from
the html then surely there has to be a way to include links to sites
and images as most written articles have them.

Absolutely.

As David suggested, so it on the server with Cocoon or AxKit, or even
statically with Saxon or similar. An XSLT stylesheet will easily transform
your XML to HTML, eg if your XML file says:

<?xml version="1.0" encoding="ISO-8859-1"?>
<file>
<article>
<title>blajhfierewr</title>
<para>e9rue 9fjfidsfjdsifs <link
uri="http://www.fake.com">fake</link> blah blah blah</para>
<image uri="http://www.picture.com/wang.jpg" />
<para>blkjfriue-r blah blah, etc, etc</para>
</article>
</file>

and your XSLT file says:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:eek:utput method="html"/>

<xsl:template match="/">
<html>
<head>
<title>
<xsl:value-of select="file/article/title"/>
</title>
<link rel="stylesheet" href="article.css" type="text/css"/>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

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

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

<xsl:template match="link">
<a href="{@uri}">
<xsl:apply-templates/>
</a>
</xsl:template>

<xsl:template match="image">
<div class="picture">
<img src="{@uri}" alt="whatever"/>
</div>
</xsl:template>

</xsl:stylesheet>

then you have much better control over what you feed your users' browsers:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>blajhfierewr</title>
<link rel="stylesheet" href="article.css" type="text/css">
</head>
<body>
<h1>blajhfierewr</h1>
<p>e9rue 9fjfidsfjdsifs <a href="http://www.fake.com">fake</a> blah
blah blah</p>
<div class="picture"><img src="http://www.picture.com/wang.jpg"
alt="whatever"></div>
<p>blkjfriue-r blah blah, etc, etc</p>
</body>
</html>

///Peter
 
A

Andy Dingley

It was somewhere outside Barstow when Frank Stallone
since the code I was using was from
W3schools that it should be compatible across the board

W3schools has no connection to the W3C

W3schools is a poor and frequently inaccurate tutorial.


Don't use DSO (datasrc etc.) It doesn't work, it never worked
widespread.

Don't use CSS, it's very restrictive.

Don't use XSLT on the client - doesn't work on every browser.

_Do_ use XSLT on the server.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top