嗨,我有以下样式表
<xsl:template match="/">
<xsl:variable name="objGen">
<xsl:value-of select="cuser:selListNodes('C:\Sitiosweb\Test\xsl\solimporta14.xml')" />
</xsl:variable>
<xsl:if test="cuser:getNodesLength($objGen)!='0'">
<xsl:for-each select="$objGen">
<xsl:sort data-type="number" order="descending" select="substring(EL01,4,4)" /><xsl:value-of select="user:IncCount()" />
<xsl:value-of disable-output-escaping="yes" select="EL01" />
<xsl:value-of disable-output-escaping="yes" select="EL02" />
<xsl:value-of disable-output-escaping="yes" select="EL03" />
<xsl:value-of disable-output-escaping="yes" select="EL04" />
<xsl:value-of disable-output-escaping="yes" select="EL05" />
</xsl:for-each>
</xsl:if>
在c#中使用以下脚本
<msxml:script language="C#" implements-prefix="cuser">
<msxml:using namespace="System.IO" />
public bool CheckFileExist(string strPath){
return File.Exists(strPath);
}
public int getNodesLength(XPathNodeIterator objNodes){
if(objNodes.Count > 0){ return(objNodes.Count); }else{ return(0); }
}
public XPathNodeIterator selListNodes(string nsetCtxt){
XPathNavigator nav;
XPathNodeIterator iterator;
XPathDocument objGenXml = new XPathDocument(nsetCtxt);
nav = objGenXml.CreateNavigator();
XPathExpression xPathExpression = nav.Compile("//Listing/Elem");
iterator = nav.Select(xPathExpression);
return( iterator );
}
xml 值为:
<Listing><Elem><EL01><![CDATA[SI-0001-14]]></EL01><EL04><![CDATA[35]]></EL04><EL02><![CDATA[351]]></EL02><EL03><![CDATA[1]]></EL03><EL04><![CDATA[35]]></EL04><EL05><![CDATA[21586]]></EL05><EL06><![CDATA[DALB, INC.]]></EL06><EL07><![CDATA[20140102]]></EL07><EL08><![CDATA[085225]]></EL08><EL09><![CDATA[]]></EL09><EL10><![CDATA[]]></EL10><EL11><![CDATA[]]></EL11><EL12><![CDATA[]]></EL12><EL13><![CDATA[]]></EL13><EL14><![CDATA[]]></EL14><EL15><![CDATA[]]></EL15></Elem><Elem><EL01><![CDATA[SI-0002-14]]></EL01><EL04><![CDATA[35]]></EL04><EL02><![CDATA[1228]]></EL02><EL03><![CDATA[1]]></EL03><EL04><![CDATA[35]]></EL04><EL05><![CDATA[22657]]></EL05><EL06><![CDATA[THE COCA COLA COMPANY]]></EL06><EL07><![CDATA[20140103]]></EL07><EL08><![CDATA[160102]]></EL08><EL09><![CDATA[]]></EL09><EL10><![CDATA[]]></EL10><EL11><![CDATA[]]></EL11><EL12><![CDATA[]]></EL12><EL13><![CDATA[]]></EL13><EL14><![CDATA[]]></EL14><EL15><![CDATA[]]></EL15></Elem></Listing>
但是在执行转换时返回错误:
To use a result tree fragment in a path expression, first convert it to a set of nodes using msxsl: node-set ().
我的问题是 XslCompiledTransform 类对 XML 树有什么限制吗?还是在使用 XPathNodeIterator 时出现错误?
提前致谢。