Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Updating XSLT Parameters using Javascript

Status
Not open for further replies.

shauncrist

Programmer
Nov 7, 2003
2
US
I've got a document that looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl?>

<FirstEl>
<SecondEl>
</SecondEl>
<Pic id="Pic1">
<PicLoc href="Pic1.gif"/>
</Pic>
<Pic id="Pic2">
<PicLoc href="Pic2.gif"/>
</Pic>
<Pic id="Pic3">
<PicLoc href="Pic3.gif"/>
</Pic>
</FirstEl>

I'm trying to display the pictures using nav buttons. It seems to work the first time I try and change pics, but after that it doesn't. The parameters appear to be changing as I look at the alert, but the pics don't update on the second try. Any ideas? TIA. Here's the XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=" xmlns:msxsl="urn:schemes-microsoft-com:xslt:>

<xsl:param name="CurPic">1</xsl:param>
<xsl:param name="PicName">Slide<xsl:value-of select="$CurSlide"/></xsl:param>
<xsl:variable name="PicNodes" select="/FirstEl/Pic" />

<xsl:template match="text()" />

<xsl:template match="FirstEl">
<html>
<head>
<title>Picture Gallery</title>

<script language="javascript" for="window" event="onload"><xsl:comment><![CDATA[
source=document.XMLDocument;
style=document.XSLDocument;
]]></xsl:comment></script>

<script language="javascript"><xsl:comment><![CDATA[
function readParms() {
el=window.event.srcElement;
oCurPicParm=document.XSLDocument.selectSingleNode("//xsl:param[@name='CurPic']");
oCurPicParm.childNodes.item(0).nodeTypedValue = el.name;
alert(oCurPicParm.childNodes.item(0).nodeTypedValue);
data.innerHTML=source.documentElement.transformNode(style);
}
]]></xsl:comment></script>

<span id="data">
<xsl:apply-templates select="Pic" />
</span>
</head>
</html>
</xsl:template>

<xsl:template match="Pic">
<xsl:if test="@id[.=$PicName]">
<body>
<div align="center">
<img align="center" height="480" width="640">
<xsl:attribute name="src">
<xsl:value-of select="PicLoc/@href" />
<xsl:attribute>
</img>
<p />
<xsl:choose>
<xsl:when test="$CurPic &gt; 1">
<img id="CurPic" src="rewind.gif" align="bottom" border="0" onClick="readParms()">
<xsl:attribute name="name">
<xsl:text>1</xsl:text>
</xsl:attribute>
</img>
<img id="CurPic" src="prev.gif" align="bottom" border="0" onClick="readParms()">
<xsl:attribute name="name">
<xsl:value-of select="$CurPic - 1" />
</xsl:attribute>
</img>
</xsl:when>
<xsl:eek:therwise>
<img id="blank" src="blank.gif" align="bottom" border="0" />
<img id="blank" src="blank.gif" align="bottom" border="0" />
</xsl:eek:therwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$CurPic &lt; count($PicNodes)">
<img id="CurPic" src="next.gif" align="bottom" border="0" onClick="readParms()">
<xsl:attribute name="name">
<xsl:value-of select="$CurPic + 1" />
</xsl:attribute>
</img>
<img id="CurPic" src="fastfwd.gif" align="bottom" border="0" onClick="readParms()">
<xsl:attribute name="name">
<xsl:value-of select="count($PicNodes)" />
</xsl:attribute>
</img>
</xsl:when>
<xsl:eek:therwise>
<img id="blank" src="blank.gif" align="bottom" border="0" />
<img id="blank" src="blank.gif" align="bottom" border="0" />
</xsl:eek:therwise>
</xsl:choose>
</div>
</body>
</xsl:if>
</xsl:template>
 
I managed to solve my own problem, so I guess this is a good tip if anyone else want to do something similar. The main template match needed to be on the root element "/". I then just added another template match for FirstEl which applied the Pic template.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top