Hi I have the following style sheet
<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>
with the following script in 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 );
}
the xml value is:
<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>
but when execute the transformation this return error:
To use a result tree fragment in a path expression, first convert it to a set of nodes using msxsl: node-set ().
my question is there any restriction for XML trees with XslCompiledTransform class? or do I have an error when using the XPathNodeIterator?
Thanks in advance.
You can simply use the XSLT
documentfunction to load and parse an XML document, there is no need to use C#. As for the error, if you really think you need to use C#, then define the variable as<xsl:variable name="objGen" select="cuser:selListNodes(...)"/>. And to check the count you can simply use the XPathcount($objGen).