不太确定这种方法的重要性,但我只是想尝试一下。不是直接在 C# 中使用 XPath 来使用 XML DOM 和读取值,是否可以将字符串作为参数传递给 XSLT 并在 XSLT 中将其用作 XPath?
C#:
.........
......
XsltArgumentList xslArg = new XsltArgumentList();
xslArg.AddParam("XPathTest", "", SomedynamicString);
XsltSettings xslsettings = new XsltSettings(false, true);
xslTransform.Load(string_xslInput, xslsettings, new XmlUrlResolver());
xslTransform.Transform(xpathXmlOrig, xslArg, objMemoryStream);
.........
......
XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:crnObj="urn:UTCCalc">
<xsl:output method="xml" indent="no"/>
<xsl:param name="XPathTest"/>
.........
.......
<xsl:template match=??$XPathTest$$??> How can the param be used?
<!--code goes here-->
</xsl:template>
.........
.......