2011-08-22 4 views
1

매우 간단한 코드로 작동하지 못했습니다. XSLT의 매개 변수는 항상 비어 있습니다. 내가 뭘 놓치고 있니? 나는 FF6을 사용하고있다. 날카로운 눈으로 도와주세요. 감사!
자바 스크립트에서 매개 변수가 전달되지 않는 XSLT

index.html을

<html> 
<head> 
<script> 
function loadXMLDoc(dname) { 
    xhttp = new XMLHttpRequest(); 
    xhttp.open("GET", dname, false); 
    xhttp.send(""); 
    return xhttp.responseXML; 
} 
function displayResult(source,styledoc,section) { 
    xml = loadXMLDoc(source); 
    xsl = loadXMLDoc(styledoc); 

    if (window.ActiveXObject) { 
     ex = xml.transformNode(xsl); 
     document.getElementById("display").innerHTML = ex; 
    } 
    else if (document.implementation && document.implementation.createDocument) { 
     xsltProcessor = new XSLTProcessor(); 
     xsltProcessor.importStylesheet(xsl); 
     xsltProcessor.setParameter(null,"section",section); 
     alert(xsltProcessor.getParameter(null,"section")); 
     resultDocument = xsltProcessor.transformToFragment(xml, document); 
     document.getElementById("display").appendChild(resultDocument); 
    } 
} 
</script> 
</head> 
<body onload="displayResult('test.xml','test.xslt','somevalue')"> 
<div id="display"/> 
</body> 
</html> 

test.xslt

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 
    <xsl:param name="section"/> 
     section=<xsl:value-of select="$section"/> 
    </xsl:template> 
</xsl:stylesheet> 

test.xml의

<?xml version="1.0" encoding="utf-8"?> 
<?xml-stylesheet type="text/xsl" href="test.xslt"?> 
<test/> 
+0

어디에서 스크립트의 firdt 부분에 매개 변수를 전달합니까? (IE 버전) – SergeS

답변

3

setParameter를()는 전역 변수 (파라미터)를 설정한다.

param 요소를 template 요소에서 이동하여 stylesheet 요소의 자식으로 만들어야합니다. 그렇지 않으면 전역 매개 변수가 재정의됩니다.

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:param name="section"/> 
<xsl:template match="/"> 
     section=<xsl:value-of select="$section"/> 
    </xsl:template> 
</xsl:stylesheet> 
+0

정말 고마워요! 당신에게 너무 쉬운 것처럼 보이는 문제는 하루 종일 저를 해 쳤습니다! –

+0

IE에서 변수를 설정하는 방법을 알고 싶으면 http://msdn.microsoft.com/en-us/library/ms762312%28v=VS.85%29.aspx;를 참조하십시오. –

관련 문제