下面是我的代码,我正在传递 Xslt 参数并检查参数是否为真,然后 xslt:text 应该返回,但我没有得到任何值。好吧,我是 xslt 的新手。
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();
}
----- 结果.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>