Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Problem using XML

  • 10-08-2011 8:21pm
    #1
    Closed Accounts Posts: 1,663 ✭✭✭


    Hi there,

    I'm using XML for the development of an online bibliography, that simply outputs the info on a particular work when you click on the particular work's title. It's fairly straight-forward.

    The problem is this: the HTML displays all of the titles of the works in a column. However, some of the titles need to be italicised, while others don't.

    Because the formatting occurs on the HTML side, does formatting have to be consistent across each of the works? ie. Is it possible to output some TITLE tags in italics, and others as normally? (which I presume requires formatting to occur on the XML side, which as far as I know can't be done)

    Any advice would be greatly appreciated.


Comments

  • Registered Users, Registered Users 2 Posts: 1,785 ✭✭✭Farls


    Not 100% sure what your trying to do from your explanation but I would guess you need to look in to putting an attribute on the title tag. You can then use the attribute to figure out if it should be formatted specially or not?


  • Registered Users, Registered Users 2 Posts: 131 ✭✭CuAnnan


    Can you give more detail on what approach you're taking, preferably a link to a demo?
    It's difficult to answer the question if we don't know the approach.


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    which I presume requires formatting to occur on the XML side

    XML is used to store and transmit data. You shouldn't be adding any forming to your xml.

    What I would do is either an attribute Italics which has a value of true/false
    on the Title XML node i.e
    [PHP]
    <books>
    <book>
    <Title Italics=true> The Bible</>
    </book>
    <book>
    <Title Italics=false> Hard Times</>
    </book>
    </books>
    [/PHP]

    I would then use XSL to transform the xml and output html. As I was processing xml via xsl I would check for the Italics=true and put an HTML italics tag around the title as required.


  • Closed Accounts Posts: 1,663 ✭✭✭evil-monkey


    Sorry for the lack of clarification. Don't have a demo going yet, but I can give ye the code if that helps:

    XML is as follows:
    <OTHER_WORKS>
            <TITLE>"Name of Essay One"</TITLE>
            <MEDIUM>Essay</MEDIUM>
            <DATE>First published 1900</DATE>
            <POSTHUMOUS>No</POSTHUMOUS>
            <FIRSTPUBLISHED>Publication Title</FIRSTPUBLISHED>
            <NOTE>-</NOTE>
        </OTHER_WORKS>
        <OTHER_WORKS>
            <TITLE>Name of Collection One</TITLE>
            <MEDIUM>Collection</MEDIUM>
            <DATE>First published 1920</DATE>
            <POSTHUMOUS>No</POSTHUMOUS>
            <FIRSTPUBLISHED>Publication Title</FIRSTPUBLISHED>
            <NOTE>-</NOTE>
    

    Then, the formatting for these is handled on the HTML as follows:
    function displayOther_WorksInfo(i) 
    
    { title=(z[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); 
    medium=(z[i].getElementsByTagName("MEDIUM")[0].childNodes[0].nodeValue); 
    date=(z[i].getElementsByTagName("DATE")[0].childNodes[0].nodeValue); 
    posthumous=(z[i].getElementsByTagName("POSTHUMOUS")[0].childNodes[0].nodeValue); 
    firstpublished=(z[i].getElementsByTagName("FIRSTPUBLISHED")[0].childNodes[0].nodeValue); 
    note=(z[i].getElementsByTagName("NOTE")[0].childNodes[0].nodeValue);
     txt="<b>Title:</b> "+title+"<br /><b>Date(s):</b> "+date+"<br /><b>Posthumous publication:</b> "+posthumous+"<br /><b>First published in:</b> <i>"+firstpublished+"</i><br /><b>Medium:</b> "+medium+"<br /><b>Note:</b> "+note; document.getElementById("showWork").innerHTML=txt; }
    
    

    As you can see, if I format TITLE to be italicised (as I have with FIRSTPUBLISHED), then all titles will be italicised, but in the examples in the XML, I only want the second text, Collection One, to be italicised, not Essay One.

    Any ideas?


  • Registered Users, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    Add an attribute
    <TITLE class="italic">"My Title"</TITLE>
    Then, in your example, you could probably do something like
    var title = z[i].getElementsByTagName("Title");
    if(title.className == "italic")
    {
        title.style.fontStyle = "italic";
    }
    

    There are much easier ways to do this, XSL for one.


  • Advertisement
Advertisement