onmouseover in xsl funktioniert nicht
Lothar
- xsl
Hallo zusammen,
wenn ich
<a onMouseOver="img_print.src='common/img/printer_grey.gif';" target="drucken" href="versionen/{$curr_version}/all.xml#info" onMouseOut="img_print='common/img/printer_white.gif';"><img name="img_print" src="common/img/printer_white.gif" height="14" border="0"/></a>
in xsl ausführe wird kein onmouseover ausgeführt. In html wird das Ganze ohne weiteres dargestellt.
Kann mir jemand sagen woran das liegt?
Hallo,
<a onMouseOver="img_print.src='common/img/printer_grey.gif';" target="drucken" href="versionen/{$curr_version}/all.xml#info" onMouseOut="img_print='common/img/printer_white.gif';"><img name="img_print" src="common/img/printer_white.gif" height="14" border="0"/></a>
in xsl ausführe wird kein onmouseover ausgeführt. In html wird das Ganze ohne weiteres dargestellt.
Könnte man da vielleicht etwas mehr Code sehen? Eventuell eine einfache Test-XML-Datei und eine minimalisierte Test-XSLT-Datei und der Information, wie Du das XSLT auf die XML-Datei anwendest (im Browser per <?xml-stylesheet?>, serverseitig - wenn ja, mit welchem Prozessor, etc.).
Allerdings gibt es auch mit dem bisherigen Code Probleme:
onMouseOver="img_print.src='common/img/printer_grey.gif';"
onMouseOut="img_print='common/img/printer_white.gif';"
Zum einen: Es ist besser, man schreibt Event-Handler komplett klein (onmouseout, onmouseover), nach HTML ist zwar beides erlaubt (und wenn Du mit XSLT HTML generierst, passt das zwar auch), nach XHTML aber nur die Kleinschreibweise, da muss man sich dann nie Gedanken machen.
Zum anderen: onmouseout - da fehlt das .src.
Zum dritten: Auf benannte Objekte mit name.irgendwas zuzugreifen sollte man in Javascript nicht mehr tun. Das ist im Endeffekt IE-Proprietärer Kram, der von anderen Browsern nur teilweise unterstützt ist. Was Du suchst ist:
onmouseover="document.images['img_print'].src='...';"
onmouseout="document.images['img_print'].src='...';"
Ob das Dein Problem löst, weiß ich nicht. Wenn es das nicht tut, bräuchte ich wie gesagt mehr Informationen, um Dir helfen zu können.
Viele Grüße,
Christian
Hallo zusammen,
hier die Codes:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='versions.xsl'?>
<dataroot>
<version>
<Version>D2.31.1</Version>
<Bezeichnung>ABC</Bezeichnung>
<Datum>05.03.2008 16:54:12</Datum>
<Status>Planung</Status>
<Status_FC>mc5col1</Status_FC>
<avail_general>Dezember 2008</avail_general>
<DVD>hook.gif</DVD>
<JetStream>hook.gif</JetStream>
</version>
<version>
<Version>V2.31.0</Version>
<Bezeichnung>ABC</Bezeichnung>
<Datum>14.03.2008 14:24:14</Datum>
<Status>Planung</Status>
<Status_FC>mc5col1</Status_FC>
<avail_general>September 2008</avail_general>
<DVD>hook.gif</DVD>
<JetStream>trans.gif</JetStream>
</version>
</dataroot>
XSl folgt
Lothar
XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:fx="#fx-functions" exclude-result-prefixes="msxsl fx">
<xsl:variable name="var_bez_Satz_01" select="/dataroot/texte_ger/bez_Satz_01"/>
...
<xsl:variable name="var_bez_Satz_77" select="/dataroot/texte_ger/bez_Satz_77"/>
<xsl:output method="html" version="4.0" indent="yes" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
<xsl:template match="//dataroot" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=UTF-8"/>
<title>Version</title>
<link rel="stylesheet" type="text/css" media="screen" href="common/css/screen.css"/>
<link rel="stylesheet" type="text/css" media="print" href="common/css/print.css"/>
<script src="common/js/common.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<div class="col4">
<table class="data zebra">
<tr>
<th class="col2"><xsl:value-of select="$var_bez_Satz_41"/></th>
<th class="col9"></th>
</tr>
<xsl:for-each select="version">
<xsl:value-of select="fx:CacheCurrentNode(.)"/>
<xsl:variable name="curr_version"><xsl:value-of select="Version"/></xsl:variable>
<tr>
<td><a href="versionen/{$curr_version}/all.xml#info" target="main"><xsl:value-of select="Bezeichnung"/><img src="../../common/img/trans.gif" height="10px"/><xsl:value-of select="Version"/></a></td>
<td>
<a onMouseOver="img_print.src='common/img/printer_grey.gif';" target="drucken" href="versionen/{$curr_version}/print.xml" onMouseOut="img_print.src='common/img/printer_white.gif';">
<img name="img_print" src="common/img/printer_white.gif" height="14" border="0"/>
</a>
</td>
</tr>
</xsl:for-each>
</table>
</div>
</div>
</body>
</html>
</xsl:template>
Und weiter XSL:
<msxsl:script language="VBScript" implements-prefix="fx" xmlns:msxsl="urn:schemas-microsoft-com:xslt"><![CDATA[ Option Explicit
Function CalculateExpressions_Detail(CurrentNode, GroupNodes)
PrepExpressions CurrentNode, GroupNodes
On Error Resume Next
CalculateExpressions_Detail = ""
End Function
Function CalculateExpressions_Global(CurrentNode, GroupNodes)
PrepExpressions CurrentNode, GroupNodes
On Error Resume Next
CalculateExpressions_Global = ""
End Function
Dim objCurrNode
Dim objCurrNodeT
Dim cGroupCount
Dim objGroupNodes
Set objGroupNodes = Nothing
Set objCurrNode = Nothing
cGroupCount = 0
Function PrepExpressions(CurrentNode, GroupNodes)
CacheCurrentNode CurrentNode
CacheGroupNodes GroupNodes
PrepExpressions = ""
End Function
Function CacheCurrentNode(objNodeList)
Set objCurrNode = objNodeList.item(0)
CacheCurrentNode = ""
End Function
Function CacheGroupNodes(objNodeList)
Set objGroupNodes = objNodeList
cGroupCount = objGroupNodes.length
CacheGroupNodes = ""
End Function
Function GroupValue_quarter(strValue)
GroupValue_quarter = Left(strValue, 4) & DatePart("q", BuildDateFromStr(strValue, False))
End Function
Function GroupValue_week(strValue)
GroupValue_week = Left(strValue, 4) & DatePart("ww", BuildDateFromStr(strValue, False))
End Function
Function GroupValue_interval(nValue, nInterval)
GroupValue_interval = Int(nValue / nInterval)
End Function
Function Page()
Page = 1
End Function
Function Pages()
Pages = 1
End Function
Function ToString(varValue)
On Error Resume Next
ToString = ""
ToString = CStr(varValue)
End Function
Function ToNumber(varValue)
On Error Resume Next
ToNumber = 0
ToNumber = CDbl(varValue)
End Function
Function FormatFromXSL(strRef, strFormat, iNumDecimals, LCID, nType)
FormatFromXSL = ToString(Format(GetValue(strRef, nType), strFormat, iNumDecimals, LCID, nType))
End Function
Function Format(varValue, strFormat, iNumDecimals, LCID, nType)
Dim FormatTemp
Dim strTemp
If IsDate(varValue) Then
Select Case strFormat
Case "General Date"
FormatTemp = FormatDateTime(varValue, vbGeneralDate)
Case "Long Date"
FormatTemp = FormatDateTime(varValue, vbLongDate)
Case "Medium Date"
FormatTemp = Day(varValue) & "-" & MonthName(Month(varValue), True) & "-" & Mid(Year(varValue), 3, 2)
Case "Short Date"
FormatTemp = FormatDateTime(varValue, vbShortDate)
Case "Long Time"
FormatTemp = FormatDateTime(varValue, vbLongTime) Case "Medium Time"
strTemp = FormatDateTime(varValue, vbLongTime)
If (IsNumeric(Mid(strTemp, 2, 1))) Then
FormatTemp = Mid(strTemp,1,5) & Mid(strTemp, 9)
Else
FormatTemp = Mid(strTemp,1,4) & Mid(strTemp, 9)
End If
Case "Short Time"
FormatTemp = FormatDateTime(varValue, vbShortTime)
Case Else
Select Case LCase(strFormat)
Case "yyyy", "q", "m", "y", "d", "w", "ww", "h", "n", "s"
FormatTemp = DatePart(LCase(strFormat), varValue)
Case Else
FormatTemp = FormatDateTime(varValue, vbGeneralDate)
End Select
End Select
ElseIf IsNumeric(varValue) Then
Select Case strFormat
Case "General Number"
FormatTemp = varValue
Case "Currency"
FormatTemp = FormatCurrencyPerLocale(varValue, iNumDecimals, LCID)
Case "Euro"
FormatTemp = FormatCurrencyPerLocale(varValue, iNumDecimals, LCID)
Case "Fixed"
If IsNumeric(iNumDecimals) Then
FormatTemp = FormatNumber(varValue, iNumDecimals, vbTrue, vbUseDefault, vbFalse)
Else
FormatTemp = FormatNumber(varValue, 2, vbTrue, vbUseDefault, vbFalse)
End If
Case "Standard"
If IsNumeric(iNumDecimals) Then
FormatTemp = FormatNumber(varValue, iNumDecimals, vbUseDefault, vbUseDefault, vbTrue)
Else
FormatTemp = FormatNumber(varValue, 2, vbUseDefault, vbUseDefault, vbTrue)
End If
Case "Percent"
If IsNumeric(iNumDecimals) Then
FormatTemp = FormatPercent(varValue, iNumDecimals)
Else
FormatTemp = FormatPercent(varValue)
End If
Case "Scientific"
Dim nExp
Dim nValue
If (varValue = 0) Then
nExp = 0
Else
nExp = Int(Log(Abs(varValue)) / Log(10))
End If
nValue = Round(CDbl(varValue)/(10^CDbl(nExp)), 2)
If (Sgn(nExp) < 0) Then
FormatTemp = FormatNumber(nValue, 2, vbTrue, vbFalse, vbFalse) & "E" & nExp
Else
FormatTemp = FormatNumber(nValue, 2, vbTrue, vbFalse, vbFalse) & "E+" & nExp
End If
Case "True/False"
If (CBool(varValue)) Then
FormatTemp = "True"
Else
FormatTemp = "False"
End If
Case "Yes/No"
If (CBool(varValue)) Then
FormatTemp = "Yes"
Else
FormatTemp = "No"
End If
Case "On/Off"
If (CBool(varValue)) Then
FormatTemp = "On"
Else
FormatTemp = "Off"
End If
Case Else
If nType = 6 Then
FormatTemp = FormatCurrencyPerLocale(varValue, iNumDecimals, LCID)
End If
End Select
End If
If IsEmpty(FormatTemp) Then FormatTemp = varValue
End If
If FHasNoContent(FormatTemp) Then
Format = " "
Else
Format = FormatTemp
End If
End Function
Function FormatCurrencyPerLocale(varValue, iNumDecimals, LCID)
Dim CurrentLCID
If LCID >< "" Then CurrentLCID = SetLocale(LCID)
If IsNumeric(iNumDecimals) Then
FormatCurrencyPerLocale = FormatCurrency(varValue, iNumDecimals)
Else
FormatCurrencyPerLocale = FormatCurrency(varValue)
End If
If Not IsEmpty(CurrentLCID) Then SetLocale CurrentLCID
End Function
Function FHasNoContent(objValue)
FHasNoContent = True
If IsNull(objValue) Then Exit Function
If IsEmpty(objValue) Then Exit Function
If Not IsObject(objValue) Then
If objValue = "" Then Exit Function
Else
If objValue Is Nothing Then Exit Function
End if
FHasNoContent = False
End Function
Function IIf(fCond, varTrue, varFalse)
If fCond Then
IIf = varTrue
Else
IIf = varFalse
End If
End Function
Function Nz(varValue, varReplace)
If FHasNoContent(varValue) Then
Nz = varReplace
Else
Nz = varValue
End If
End Function
Function Sum(strExpr)
Dim nSum, i
nSum = 0
Set objCurrNodeT = objCurrNode
For i = 0 To cGroupCount - 1
Set objCurrNode = objGroupNodes.item(i)
nSum = nSum + ToNumber(Eval(strExpr))
Next
Set objCurrNode = objCurrNodeT
Sum = nSum
End Function
Und weiter:
Function Count(strExpr)
Dim nCount, i
If strExpr = "*" Then
Count = cGroupCount
Exit Function
End If
Set objCurrNodeT = objCurrNode
nCount = 0
For i = 0 To cGroupCount - 1
Set objCurrNode = objGroupNodes.item(i)
If Not FHasNoContent(Eval(strExpr)) Then
nCount = nCount + 1
End If
Next
Set objCurrNode = objCurrNodeT
Count = nCount
End Function
Function Avg(strExpr)
Dim nSum
Dim nCount
nSum = Sum(strExpr)
nCount = Count(strExpr)
If nCount > 0 Then
Avg = nSum / nCount
Else
Avg = nSum
End If
End Function
Function Min(strExpr)
Dim varMin, i
Dim varTemp
Set objCurrNodeT = objCurrNode
For i = 0 To cGroupCount - 1
Set objCurrNode = objGroupNodes.item(i)
varTemp = Eval(strExpr)
If IsEmpty(varMin) Or (varTemp < varMin) Then
varMin = varTemp
End If
Next
Set objCurrNode = objCurrNodeT
Min = varMin
End Function
Function Max(strExpr)
Dim varMax, i
Dim varTemp
varMax = Eval(strExpr)
Set objCurrNodeT = objCurrNode
For i = 0 To cGroupCount - 1
Set objCurrNode = objGroupNodes.item(i)
varTemp = Eval(strExpr)
If IsEmpty(varMax) Or (varTemp > varMax) Then
varMax = varTemp
End If
Next
Set objCurrNode = objCurrNodeT
Max = varMax
End Function
Function GetValue(strRef, nType)
' Set Null as the default return value
GetValue = Null
' Return Null if anything goes wrong
On Error Resume Next
Dim objNode
Set objNode = objCurrNode.selectSingleNode(strRef)
If (objNode Is Nothing) Or IsNull(objNode) Or IsEmpty(objNode) Or Not IsObject(objNode) Then
Exit Function
End If
Dim CurrentLCID
CurrentLCID = SetLocale(1033)
Select Case nType
Case 2 ' adSmallInt
GetValue = CLng(objNode.text)
Case 3 ' adInteger
GetValue = CLng(objNode.text)
Case 20 ' adBigInt
GetValue = CLng(objNode.text)
Case 17 ' adUnsignedTinyInt
GetValue = CLng(objNode.text)
Case 18 ' adUnsignedSmallInt
GetValue = CLng(objNode.text)
Case 19 ' adUnsignedInt
GetValue = CLng(objNode.text)
Case 21 ' adUnsignedBigInt
GetValue = CLng(objNode.text)
Case 4 ' adSingle
GetValue = CDbl(objNode.text)
Case 5 ' adDouble
GetValue = CDbl(objNode.text)
Case 6 ' adCurrency
GetValue = CCur(objNode.text)
Case 14 ' adDecimal
GetValue = CDbl(objNode.text)
Case 131 ' adNumeric
GetValue = CDbl(objNode.text)
Case 139 ' adVarNumeric
GetValue = CDbl(objNode.text)
Case 11 ' adBoolean
GetValue = CBool(objNode.text)
Case 7 ' adDate
GetValue = BuildDateFromStr(objNode.text, True)
Case 133 ' adDBDate
GetValue = BuildDateFromStr(objNode.text, True)
Case 134 ' adDBTime
GetValue = BuildDateFromStr(objNode.text, True)
Case 135 ' adDBTimeStamp
GetValue = BuildDateFromStr(objNode.text, True)
Case 8 ' adBSTR
GetValue = objNode.text
Case 120 ' adChar
GetValue = objNode.text
Case 200 ' adVarChar
GetValue = objNode.text
Case 201 ' adLongVarChar
GetValue = objNode.text
Case 130 ' adWChar:
GetValue = objNode.text
Case 202 ' adVarWChar
GetValue = objNode.text
Case 203 ' adLongVarWChar
GetValue = objNode.text
Case -7 ' Special value used to get just the date.
GetValue = BuildDateFromStr(objNode.text, False)
Case Else
GetValue = objNode.text
End Select
SetLocale CurrentLCID
End Function
Dim gStaticDate
Function StaticDate()
If IsEmpty(gStaticDate) Then gStaticDate = GetValue("/*/@generated", -7)
StaticDate = gStaticDate
End Function
Dim gStaticNow
Function StaticNow()
If IsEmpty(gStaticNow) Then gStaticNow = GetValue("/*/@generated", 7)
StaticNow = gStaticNow
End Function
Function BuildDateFromStr(strDate, fIncludeTime)
Dim CurrentLCID
CurrentLCID = SetLocale(1033)
' This requires that the Locale be set to en-us (1033).
BuildDateFromStr = CDate(Left(strDate,10))
If (fIncludeTime) Then
BuildDateFromStr = BuildDateFromStr + CDate(Right(strDate,8))
End If
SetLocale CurrentLCID
End Function
Function ArrayItem(arr, index)
If index > UBound(arr) Then
ArrayItem = ""
Else
ArrayItem = arr(index)
End If
End Function
Function HyperlinkPartFromNodeList(nodelist, nPart)
If nodelist.length = 0 Then
HyperlinkPartFromNodeList = ""
Else
HyperlinkPartFromNodeList = HyperlinkPartFromString(nodelist.item(0).text, nPart)
End If
End Function
Function HyperlinkPart(strRef, nPart)
HyperlinkPart = HyperlinkPartFromString(GetValue(strRef, 200), nPart)
End Function
Function HyperlinkPartFromString(strHyperlink, nPart)
Dim arrParts
Dim strHyperlinkPart
Dim strAddress, strSubAddress
arrParts = Split(strHyperlink, "#")
Select Case nPart
Case 0 ' acDisplayedValue
strHyperlinkPart = ArrayItem(arrParts, 0)
If strHyperlinkPart = "" Then
strAddress = ArrayItem(arrParts, 1)
strSubAddress = ArrayItem(arrParts, 2)
If strAddress = "" and strSubAddress = "" Then
strHyperlinkPart = ""
ElseIf strSubAddress = "" Then
strHyperlinkPart = strAddress
ElseIf strAddress = "" Then
strHyperlinkPart = strSubAddress
Else
strHyperlinkPart = strAddress & " - " & strSubAddress
End If
End If
Case 1 ' acDisplayText
strHyperlinkPart = ArrayItem(arrParts, 0)
Case 2 ' acAddress
strHyperlinkPart = ArrayItem(arrParts, 1)
Case 3 ' acSubAddress
strHyperlinkPart = ArrayItem(arrParts, 2)
Case 4 ' acScreenTip
strHyperlinkPart = ArrayItem(arrParts, 3)
Case 5 ' acFullAddress
strAddress = ArrayItem(arrParts, 1)
strSubAddress = ArrayItem(arrParts, 2)
If strAddress = "" and strSubAddress = "" Then
strHyperlinkPart = "#"
ElseIf strSubAddress = "" Then
strHyperlinkPart = strAddress
Else
strHyperlinkPart = strAddress & "#" & strSubAddress
End If
End Select
HyperlinkPartFromString = strHyperlinkPart
End Function
]]></msxsl:script>
</xsl:stylesheet>
Es wäre schön, wenn ich das VBScript gegen Javascript ersetzen könnte, habe dazu aber noch keinen Lösungsansatz.
Hallo!
Nichts für ungut, aber könntest Du bitte nächstes Mal das XSLT auf das Wesentliche reduzieren? Das ganze VBScript-Zeug ist nämlich absolut nicht relevant für das Problem.
Du hast in Deiner Ausgabe gleich zwei Probleme:
Wie ich bereits sagte, ist img_print.src = '...' der falsche Weg, um Bilder anzusprechen. Korrekt wäre document.images['img_print'].src = '...';
Aber selbst das wird Dir nichts nützen. Denn: Du generierst viele solcher Bilder, nicht nur eines. Dann musst Du natürlich die Bilder auch eindeutig identifizeren können, um in JS gerade das richtige Bild austauschen zu können.
Also:
Unter
<xsl:variable name="curr_version">
<xsl:value-of select="Version"/>
</xsl:variable>
setze noch ein:
<xsl:variable name="curr_version_id" select="concat('img_print_', translate($curr_version, '.', '_'))" />
Das erzeugt Dir eine Variable $curr_version_id, die einen eindeutigen Namen für Dein Bild enthält, also z.B. img_print_D2_31_1 (das translate ersetzt den '.', der in name="..." eher ungünstig ist, durch einen '_').
Dann setzt Du das name-Attribut des Bildes entsprechend und nutzt den Wert auch in Deinem generierten Javascript:
<a onmouseover="document.images['{$curr_version_id}'].src='.../printer_grey.gif';" target="drucken" href="versionen/{$curr_version}/print.xml" onmouseout="document.images['{$curr_version_id}'].src='.../printer_white.gif';">
<img name="{$curr_version_id}" src=".../printer_white.gif" height="14" border="0" alt="Drucken" />
</a>
Dann sollte Dein Mouseover auch funktionieren.
Viele Grüße,
Christian
PS: Übrigens: <xsl:variable name="curr_version" select="string(Version)" />
ist in meinen Augen viel sinnvoller, als Deine Konstruktion mit variable + value-of. Nur als kleine Anmerkung.
Hallo Christian,
vielen Dank erstmal, klappt einwandfrei.
Den VB-Script anteuil habe ich hier ins Forum kopiert, weil Ihr wissen wolltet mit welchem Parser das Ganze läuft.
Lothar
Als erstes: XSL ist zur Transformation von XML Daten da.
Zweitens: Die Frage, warum kein Mouseover funktioniert, liegt dann eher an dem Ergebnis, was "hinten" rauskommt, nachdem der Parser mit hilfe des xsl files die Datei transformiert hat. Wenn also kein mouseover funktioniert, dann stimmt etwas nicht mit deinem (x)html code, den müsstest du dann entweder mal im html Bereich als Frage einstellen oder aber du weisst, woran der Fehler liegt und fragst dann hier nochmal, warum dein xsl file es so falsch ausgibt, und dann sehen wir weiter ;-)
Also rechte maustaste im browser, quellcode anzeigen lassen und eventuell dann die frage noch mal genauer stellen.
Als kleiner Tip:
so etwas: href="versionen/{$curr_version}/all.xml#info"
würde ich eher so schreiben: href="{concat('versionen/',$curr_version,'/all.xml#info')}"
oder aber sauber mit:
<xsl:attribute name="href">
xsl:textversionen/</xsl:text>
<xsl:value-of select="$curr_version"/>
xsl:text/all.xml#info</xsl:text>
</xsl:attribute>
Hallo zusammen,
wenn ich
<a onMouseOver="img_print.src='common/img/printer_grey.gif';" target="drucken" href="versionen/{$curr_version}/all.xml#info" onMouseOut="img_print='common/img/printer_white.gif';"><img name="img_print" src="common/img/printer_white.gif" height="14" border="0"/></a>
in xsl ausführe wird kein onmouseover ausgeführt. In html wird das Ganze ohne weiteres dargestellt.
Kann mir jemand sagen woran das liegt?