Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 31st, 2006, 02:55 PM
cathy@t2studios.net
Guest
 
Posts: n/a
Default 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.

  #2  
Old August 1st, 2006, 04:35 AM
Gadrin@gmail.com
Guest
 
Posts: n/a
Default Re: Display and filter xml content in drop-down menu

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>

  #3  
Old August 1st, 2006, 12:55 PM
Tigger25
Guest
 
Posts: n/a
Default Re: Display and filter xml content in drop-down menu

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?

  #4  
Old August 1st, 2006, 03:25 PM
Gadrin@gmail.com
Guest
 
Posts: n/a
Default Re: Display and filter xml content in drop-down menu

I sent you an email with the files.

Gadrin.

  #5  
Old August 1st, 2006, 04:05 PM
Tigger25
Guest
 
Posts: n/a
Default Re: Display and filter xml content in drop-down menu

Thanks. That all works brilliantly now.

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles