...

View Full Version : Advise on including hyperlinks in XML pages



brothercake
01-23-2003, 02:38 AM
I'm looking for a way of doing an apparently simple thing - hyperlink arbitrary phrases. Say I have something like

<para>here is some text containg a link to a different section of this website</para>

And I want "a link" to be a link (I know that's not good link text; it's just an example!). I dont really want to go:

<para>here is some text containing <url href="page.html">a link</url> to a different section of this website</para>

But it's not what I want - I wouldn't be able to retrieve the whole paragraph of text using <xsl:value-of/>; in fact I'm unsure how to parse that at all - given that there may be 0 or more <url/> elements inside each <para> ... how would I be able to end up with anything other than bits of plain text followed by each of the links? Is it possible to use <xsl:for-each/> to iterate through nodes recursively and then compile the results at the end ..?

But anyway, it just feels wrong; like i'm forcing metadata to be inside a data node. So my alternative idea was something like

<para url="page.html" text="a link"> ... </para>

which would be easy to parse into linked text, by getting the XSL to generate PHP, and then preg_replace the text which matches attribute values; and it reflects the nature of the link data. But it's not extensible ... not without "url1" "url2" etc ... or is there an array syntax for attributes ?

Long question I know ... I'd appreciate any suggestions or comments.

jkd
01-23-2003, 02:50 AM
Why not use XLink, which semantically makes sense in XML, then pull out link info into an <a> when transforming to XHTML?

brothercake
01-23-2003, 03:02 AM
Yeah that looks good; so am I right in saying that

xmlns:xlink="http://www.w3.org/1999/xlink"

needs to go in my root element, and then I define xlink:type, xlink:href etc. in <!ATTLIST>s ?

jkd
01-23-2003, 03:36 AM
yuppers. :)

You can even give the root element that attribute and value through the DTD without you needing to declare it in the XML doc...

brothercake
01-23-2003, 02:52 PM
what, by defining that attribute for the root element with a fixed default value ..?

cool :)

jkd
01-23-2003, 05:09 PM
Originally posted by brothercake
what, by defining that attribute for the root element with a fixed default value ..?

yup.

CRASH_OVERRIDE
01-25-2003, 01:11 AM
Possibly another way, and spare me if Im wrong as I have never tried it, but could you use <![CDATA[ text...links...etc... ]]>?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum