4

I also have an xml file containing news headlines, there is a second xml containing full news stories. These xml files are linked by a unique story ID.

I am building a single web page which has 2 sections. In one section is a list of stories, which I can generate using XSLT and the headline xml file. I need to update the second section based on whichever link is clicked.

This is the xslt which generates the headline section

<xsl:for-each select="response/newsList/news">
    <div class="newsListItem">
      <h2><xsl:value-of select="title" /></h2>
      <p><xsl:value-of select="shortText" /></p>
      <p>
      <xsl:element name="a">
      <xsl:attribute name="href">
        index.html?newsid=<xsl:value-of select="id"/>
      </xsl:attribute>
      <xsl:attribute name="rel">
        <xsl:value-of select="id"/>
      </xsl:attribute>
      <xsl:attribute name="onclick">
        removeContent(); displayXMLItem('newsItem','newsFullArticles.xml','articleFull.xsl'); return false;
      </xsl:attribute>
      <xsl:text>More</xsl:text>
      </xsl:element>

      </p>
    </div>
</xsl:for-each>

The xslt for the second section is

  <xsl:for-each select="response/newsList/news[id=?]">
    <div class="newsListItem">
      <h2>The Full Article</h2>
      <p><xsl:value-of select="text" /></p>
    </div>
  </xsl:for-each>

I understand that I need to somehow update the id=? to indicate which story I want to show but I can see how to do it. Unfortunately I can not use any server side language, it all has to be done in vanilla JavaScript.

The html page where I am calling everything is here

function loadXMLDoc(dname)
{
if (window.ActiveXObject)
{
  xhttp=new ActiveXObject("Msxml2.XMLHTTP.3.0");
}
else
{
  xhttp=new XMLHttpRequest();
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}

var displayXMLItem = function(container, xmlFileToParse, xslTemplate,itemIdentifier)
{
xml=loadXMLDoc(xmlFileToParse);
xsl=loadXMLDoc(xslTemplate);
// code for IE
if (window.ActiveXObject)
  {
  ex=xml.transformNode(xsl);
  document.getElementById(newsListContainer).innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml,document);
  document.getElementById(container).appendChild(resultDocument);
  }
}
var removeContent = function(){
document.getElementById('newsItem').innerHTML = "";
}

If anyone can point me in the right direction I would appreciate it. Is what I am trying to do possible, without a server side language? Sorry if this isn't making sense, I have been banging my head against a brick wall for the past couple of hours so it seems.

Thanks in advance.

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.