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

Discussion in 'XML' started by Frank Stallone, Mar 22, 2005.

  1. 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.
    Frank Stallone, Mar 22, 2005
    #1
    1. Advertising

  2. David Dorward, Mar 22, 2005
    #2
    1. Advertising

  3. 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.



    On Tue, 22 Mar 2005 21:54:42 +0000, David Dorward <>
    wrote:

    >Frank Stallone wrote:
    >
    >> <span datasrc="#xmltext" datafld="article"></span>

    >
    >Short answer:
    >Transform it with XSLT on the server, not with that weird, non-standard,
    >badly supported stuff on the client.
    >
    >Long answer:
    >http://groups-beta.google.com/group...b384557b66e/d07096edf920d707#d07096edf920d707
    Frank Stallone, Mar 22, 2005
    #3
  4. Frank Stallone

    Peter Flynn Guest

    Frank Stallone wrote:

    > 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
    --
    sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
    &;top"
    Peter Flynn, Mar 22, 2005
    #4
  5. Frank Stallone

    Andy Dingley Guest

    It was somewhere outside Barstow when Frank Stallone
    <> wrote:

    >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.
    Andy Dingley, Mar 23, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kaidi
    Replies:
    5
    Views:
    457
    Andrew Thompson
    Jan 4, 2004
  2. Nathan Sokalski

    Converting Relative URLs into Absolute URLs

    Nathan Sokalski, Aug 11, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    731
    Sriram Srivatsan
    Aug 12, 2008
  3. Adam Monsen

    JDBC URLs ...not really URLs?

    Adam Monsen, Feb 6, 2009, in forum: Java
    Replies:
    11
    Views:
    6,129
    Adam Monsen
    Feb 8, 2009
  4. Steve T.

    dynamic URLS convert to static URLS for search engines

    Steve T., Mar 1, 2004, in forum: ASP .Net Web Services
    Replies:
    7
    Views:
    275
    Steve T.
    Mar 4, 2004
  5. Replies:
    2
    Views:
    81
Loading...

Share This Page