Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:53:07+00:00 2026-05-30T23:53:07+00:00

Here is where I’m stuck (have a look at the files below to getter

  • 0

Here is where I’m stuck (have a look at the files below to getter a better picture) :

value.singleNodeValue.setAttribute("select", "books/scifi[year>1962]");

How can I add more “filters” to the above? for example: [year>1962 && author=Dan Larson] I know this isn’t the correct syntax because it’s not working so how do I do it?

XML file:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="books.xsl"?>
<!DOCTYPE books [
<!ENTITY Aring  "&amp;#197;" >
<!ENTITY aring  "&amp;#229;" >
<!ENTITY agrave "&amp;#224;" >
<!ENTITY aacute "&amp;#225;" >
<!ENTITY auml   "&amp;#228;" >
<!ENTITY ccedil "&amp;#231;" >
<!ENTITY eacute "&amp;#233;" >
<!ENTITY egrave "&amp;#232;" >
<!ENTITY iacute "&amp;#237;" >
<!ENTITY iuml   "&amp;#239;" >
<!ENTITY oacute "&amp;#243;" >
<!ENTITY ocirc  "&amp;#244;" >
<!ENTITY oslash "&amp;#248;" >
<!ENTITY Ouml   "&amp;#214;" >
<!ENTITY ouml   "&amp;#246;" >
<!ENTITY uuml   "&amp;#252;" >
]>

<books>

  <scifi key="DanlarsC83">
    <shelfcode>scif/all/83</shelfcode>
    <author>Dan Larson</author>,
    <author>James Roberts</author>,
    <author>Chris Rupert</author>,
    <title>The Game</title>,
    <pages>126-212</pages>,
    <year>1965</year>,
    <booktitle>SCI</booktitle>,
  </scifi>

  <scifi key="RobDwightS45">
    <shelfcode>scif/all/45</shelfcode>
    <author>Dan Larson</author>,
    <author>Christine Dwight</author>,
    <title>Hopes</title>,
    <pages>113-242</pages>,
    <year>1973</year>,
    <booktitle>SCI</booktitle>,
  </scifi>

  <scifi key="MarkJohnsC52">
    <shelfcode>scif/all/52</shelfcode>
    <author>Dan Larson</author>,
    <title>Incognitum</title>,
    <pages>131-420</pages>,
    <year>1949</year>,
    <booktitle>SCI</booktitle>,
  </scifi>

 </books>

XSL file:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <center><h1>TOM's Sci-Fi</h1>
    <table border="1">
    <tr>
      <th>Title</th>
      <th>Authors</th>
      <th>Pages</th>
      <th>Year</th>
    </tr>
      <xsl:for-each select="books/scifi">
      <xsl:sort select="year"/>
    <tr>
      <td><center><xsl:value-of select="title"/></center></td>
      <td>
       <xsl:for-each select="author">
        <p><xsl:value-of select="."/></p>
        </xsl:for-each>
      </td> 
      <td><xsl:value-of select="pages"/></td>
      <td><xsl:value-of select="year"/></td>
    </tr>
    </xsl:for-each>
    </table>
    </center>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

HTML file:

<html>

<script type="text/javascript">

var moz = (typeof document.implementation.createDocument != 'undefined');
var ie =  (typeof window.ActiveXObject != 'undefined');

function loadXML(file)
{
  var xmlDoc;
  if (moz)
    xmlDoc = document.implementation.createDocument("", "", null);
  else if (ie)
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async = false;
  xmlDoc.validateOnParse=false;
  xmlDoc.load(file);
  return xmlDoc;
}
</script>

<body id="target4">
<script type="text/javascript">

 function filterTable(f)


{
  var xmlDoc = loadXML("books.xml");
  var stylesheet = loadXML("books.xsl");
  var moz = (typeof document.implementation.createDocument != 'undefined');
  var ie = (typeof window.ActiveXObject != 'undefined');

  if (moz)
  {
    var nsResolver = stylesheet.createNSResolver( stylesheet.ownerDocument == null ? stylesheet.documentElement : stylesheet.ownerDocument.documentElement);

    var value = stylesheet.evaluate("//xsl:template[@match='/']//xsl:for-each", stylesheet, nsResolver, XPathResult.ANY_UNORDERED_NODE_TYPE, null);

    var author = document.getElementById("inauthor").value;
    var title = document.getElementById("intitle").value;
    var year = document.getElementById("inyear").value;
    var filter = "";

    if (author != "")
    {
       filter= filter + "author='" + author.substr(1) + "'";
    }

    if (title != "")
    {
        if (filter != "") filter = filter + " and ";
        filter = filter + "title='" + title.substr(1) + "'";
    }

    if (year != "")
    {
        if (filter != "") filter = filter + " and ";
        filter = filter + "year" + year.substr(0) + year.substr(1);
    }

    value.singleNodeValue.setAttribute("select", "books/scifi[filter]");

    var proc = new XSLTProcessor();
    proc.importStylesheet(stylesheet);
    var resultFragment = proc.transformToFragment(xmlDoc, document);
    document.getElementById("target4").appendChild(resultFragment);
  }

  else if (ie)
  {

    var value = stylesheet.selectSingleNode("//xsl:template[@match='/']//xsl:for-each");

    value.setAttribute("select", "books/scifi[filter]");

    document.write(xmlDoc.transformNode(stylesheet));
  }
  }

<center>
  <table border="1" cellpadding="8">
  <tr><td>
  </br>
    <form>
      <center>
        <b> search by </b>
        Author(s): <input type="text" name="authors" />
        Title: <input type="text" name="title" />
        Year: <input type="text" name="year" />
        No of Authors: <input type="text" name="numauth" />
        </br></br>
        <b> sort by</b>
        <input type="radio" name="sorter" value="author" />author
        <input type="radio" name="sorter" value="title" />title
        <input type="radio" name="sorter" value="year" />year
        <input type="radio" name="sorter" value="pages" />pages</br></br>
        <input type="button" value="Display" onClick="filterTable(this.form)"/>
     </center>
    </form>
   </td></tr>
   </table>
</center>

</body>

</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:53:08+00:00Added an answer on May 30, 2026 at 11:53 pm
    [year>1962 and author='Dan Larson']
    

    To set the values dynamically based on user selected values:

    1. Give the inputs an id (e.g. <input type="text name="authors" id="author">).
    2. Use the code below

    (this is not tested!)

    var author = document.getElementById("author").value;
    var title = document.getElementById("title").value;
    var year = document.getElementById("year").value;
    
    var filter = "";
    if (authors != "") filter += "author='" + author + "'";
    if (title != "") {
        if (filter != "") filter += " and ";
        filter += "title='" + title + "'";
    }
    if (year != "") {
        if (filter != "") filter += " and ";
        filter += "year>" + year;
    }
    if (filter != "") filter = "[" + filter + "]";
    
    value.setAttribute("select", "books/scifi" + filter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here's the basic setup: I have a thin bar at the top of a
Here is my problem : I have a post controller with the action create.
Here is an example: I have the generic type called Account. I wish to
Here is the problem that I am trying to solve. I have two folders
Here's my database: id name parent_id 1 Computers NULL 2 Apple 1 3 Books
Here is my scenario. I have a website running under AppPool1 and that works
Here is my problem.. I have the option to create(add) two new input fields,
Here are the tables I have: Table A which has entries with item and
Here's the code I have. It works. The only problem is that the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.