0
下面是我的代碼,我傳遞Xslt參數&檢查參數是否爲真然後xslt:文本應該返回,但我不geting任何值。我是新的xslt 。xslt參數傳遞問題 - <xsl:text>返回空結果
string filename = "tmp.xml";
string stylesheet = "result.xslt";
protected void Page_Load(object sender, EventArgs e)
{
//Create the XslTransform and load the stylesheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(stylesheet);
//Load the XML data file.
XPathDocument doc = new XPathDocument(filename);
XsltArgumentList obj = new XsltArgumentList();
bool category = ConfigurationManager.AppSettings["Code"].Contains("Software");
obj.AddParam("category", "", category);
//Create an XmlTextWriter to output to the console.
StringWriter sw = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(sw);
writer.Formatting = Formatting.Indented;
//Transform the file.
xslt.Transform(doc, obj, writer, null);
writer.Close();
}
----- result.xslt文件----
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts">
<xsl:param name="category" />
<xsl:template match="data">
<xsl:if test="$category=true">
<xsl:text>Software is avilable.</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
------ tmp.xml文件-------------
<?xml version="1.0" encoding="utf-8" ?>
<data>
<circle>
<radius>12</radius>
</circle>
<circle>
<radius>37.5</radius>
</circle>
</data>
這是非常有用的信息,謝謝 – intelliWork 2013-03-08 17:33:05