Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Advice on including hyperlinks in XML pages

    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.
    Last edited by brothercake; 01-23-2003 at 01:44 AM.

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Why not use XLink, which semantically makes sense in XML, then pull out link info into an <a> when transforming to XHTML?

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ?

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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...

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what, by defining that attribute for the root element with a fixed default value ..?

    cool

  • #6
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Originally posted by brothercake
    what, by defining that attribute for the root element with a fixed default value ..?
    yup.

  • #7
    Regular Coder
    Join Date
    Aug 2002
    Location
    IN, USA
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Possibly another way, and spare me if Im wrong as I have never tried it, but could you use <![CDATA[ text...links...etc... ]]>?
    Just call me Crash...
    "Crash- and BURN!"
    -Cereal Killer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •