473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Display and filter xml content in drop-down menu

Hi All,

I am having problems displaying content relevant to the option selected
in a drop-down menu. I have an xml document which is running content
through Flash and I need to have the same content on a web page. I am
working in Dreamweaver 8 and code in asp.net (vb).

I need to have a drop-down menu listing available news articles, when
one is selected the article should appear on the page. I have currently
managed to populate the list, but as of yet I have had no luck in
binding it to the page content. I am sure that this is quite simple,
but I am fairly new to xslt etc.

Here is my xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="../news.xsl" type="text/xsl"?>
<news>
<news name="article one">
<description>Article one content</description>
<title>the full title of article one</title>
</news>
<news name="article two">
<description>Article two content</description>
<title>the full title of article two</title>
</news>
</news>

Here is my xsl:

<!-- DWXMLSource="data/news.xml" --><!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"
doctype-public="-//W3C//XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>my page</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="newstop"><select>
<p>
<xsl:for-each select="news/news">
<option><xsl:value-of select="@name"/></option>
</xsl:for-each>
</p>
</select>
<p class="title"><xsl:value-of select="news/news/title"/></p>
</div>
<div id="news">
<p><xsl:value-of select="news/news/description"/></p>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Thanks in advance.

Jul 31 '06 #1
4 3959
I made some changes to the XSL file. I'm used to VBScript so you might
have to re-code using the language you prefer.

This works on my PC with a few changes from the XML you provided....

notably I changed:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="news.xsl" type="text/xsl"?>
<news>
<newsarticle name="article one">
<description>Article one content</description>
<title>the full title of article one</title>
</newsarticle>
<newsarticle name="article two">
<description>Article two content</description>
<title>the full title of article two</title>
</newsarticle>
</news>

I felt "news/news" was too confusing...so I changed to
"news/newsarticle"...

but you should be able to re-produce on your own...
<!-- DWXMLSource="data/news.xml" --><!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"
doctype-public="-//W3C//XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>my page</title>
<link href="css.css" rel="stylesheet" type="text/css" />

<SCRIPT LANGUAGE="VBScript"><![CDATA[

function ShowArticle()
dim clicked, ArticleTitle, x, ThisDiv
' find out which OPTION was clicked...
clicked = document.getElementByID("A77").options.selectedInd ex
' get its text (article name)
ArticleTitle =
document.getElementByID("A77").getElementsByTagNam e("OPTION").item(clicked).innerText
'alert ArticleTitle

' loop thru all the DIVs inside the Articles DIV...
for x = 0 to
document.getElementByID("Articles").getElementsbyT agName("DIV").length-1
set ThisDiv =
document.getElementByID("Articles").getElementsbyT agName("DIV").item(x)
'alert ThisDiv.name
' compare their .names to the selected title...then set their
visibility...
if ThisDiv.name = ArticleTitle then
ThisDiv.style.display = ""
else
ThisDiv.style.display = "none"
end if
next
end function

]]></SCRIPT>

</head>
<body>

<div id="newstop">
<select id="A77" onchange="ShowArticle()"<!-- give SELECT an ID and
an ONCHANGE event -->
<xsl:for-each select="news/newsarticle">
<option>
<xsl:value-of select="@name"/>
</option>
</xsl:for-each>
</select>
</div>

<div id="Articles" <!-- Create DIV to hold all the articles -->

<xsl:for-each select="news/newsarticle"<!-- Create a DIV for each
article -->
<div>
<xsl:attribute name="name"><xsl:value-of
select="@name"/></xsl:attribute<!-- give each DIV a NAME attribute
-->
<xsl:attribute name="style">display:none</xsl:attribute<!-- make
sure each Article is invisible to start -->
<p><xsl:value-of select="title"/></p>
<p><xsl:value-of select="description"/></p>
</div>
</xsl:for-each>

</div>

</body>
</html>
</xsl:template>
</xsl:stylesheet>

Aug 1 '06 #2
Thanks for your code, but I couldn't get it to run. I copied all of
your code and swapped it in, but I get this error-
Type mismatch: 'ShowArticle'.

What do you think the problem could be?

Aug 1 '06 #3
I sent you an email with the files.

Gadrin.

Aug 1 '06 #4
Thanks. That all works brilliantly now.

Aug 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sue | last post by:
Anyone have any ideas on why the code below will show up in a browser's sourcecode as an empty table, and is not visible? aspx: <headertemplate> <asp:Table ID="MyTable" runat="server" /> ...
17
by: perryche | last post by:
I have 5records, e.g. Rc1, Rc2, Rc3..., when user open up a form, I want it to open to a particular record (say Rc3) then when user chooses the Record Selector , it will go to Rc2 and , it will go...
3
by: Brad | last post by:
I have a response filter which injects "standard" html into my pages. The filter works fine when the initial stream is small enough not to buffer...or....if I have a large unbuffered stream (i.e. I...
3
by: Shapper | last post by:
Hello, In a database table named t_content I have the following records: id page name content 1 index introduction Introduction Text 2 ...
1
by: Luurs | last post by:
Hi All, I've been using a asp-label in the HTML <headsection for quite some time in order to dynamically generate meta-keywords,-description, css and js references. Though the actual...
2
by: j.m.osterman | last post by:
I haven't found exactly what I've been trying to do. All I am trying to do for now is just display usernames from Active Directory into a ListBox control on a page. I have found some code...
6
by: Ken Fine | last post by:
I'm using SQLDataSource, which generates some kind of dataset, and then I attach that datasource to various data display controls such as DataList and repeater which loop through to the end of the...
0
by: mpdoreilly | last post by:
Hi, I've a webservice that has several typical webmethods that clients call and get responses from. (Side note: The websriivce is actually to implement the server side of tr-069, the protocol...
15
by: cssExp | last post by:
hello, Rather than going on a wild explanation on what's the the problem, it'll be much quicker and easier if i let you look at it yourself, so I'll post my page source (actual contents taken out,...
0
by: elliott | last post by:
Hello, I'm trying to use a C# IHttpModule to install a Response filter however IIS keeps removing the Content-Encoding header from the response; but all the other headers I set stay intact. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.