Free Support Forum - aspose.com

Msxsl:node-set()

I want to use msxsl:node-set() to calculate an overall total of some subsections.

My xsl is working correct when I use it as a stylesheet to my xml page, the totals are calculate and the page is rendered well.

When I use te same xsl and xml to render with aspose.pdf , the calculation is not done and results in 0.

I think that the xsl:variable has no content.

xsl snippet:
<xsl:variable name="tmpTotal">
<xsl:for-each select="vakken/vak">
<item>
<xsl:value-of select="puntenDW"/>
item>
xsl:for-each>
xsl:variable>

<xsl:variable name="myTotal">
<xsl:value-of select="sum(msxsl:node-set($tmpTotal)/item)"/>
xsl:variable>
totaal:<xsl:value-of select="$myTotal"/>

xml snippet:

<rapport>
<vakken>
<vak>
<vaknaam>GODSDIENST</vaknaam>
<puntenDW>70</puntenDW>
<tebehalenDW>20</tebehalenDW>
<puntenEX>80</puntenEX>
<tebehalenEX>30</tebehalenEX>
</vak>
<vak>
<vaknaam>LO</vaknaam>
<puntenDW>70</puntenDW>
<tebehalenDW>20</tebehalenDW>
<puntenEX>49</puntenEX>
<tebehalenEX>30</tebehalenEX>
</vak>
</vakken>
</rapport>

Hi,

Thank you for considering Aspose.

I am not familiar with xslt. When I use the following code to test, the result for is 0:

XslTransform xsl = new XslTransform();
xsl.Load("d:/CSharp/Pdf-bak/Xml/Test/content.xslt");

xsl.Transform("d:/CSharp/Pdf-bak/Xml/Test/content.xml","d:/test/test.xml",null);

How do you use it in your application?

Thank you for the quick answer

below is the code I use to bind my xml file to xsl and produce my pdf-file. This all works great.
doc_xml.Load(Server.MapPath("xmltest.xml"));
pdf1.BindXML(doc_xml, Server.MapPath("xsltfile.xsl"));
pdf1.Save("c:\\H.pdf");

I was perfectly able to create a " xsl:variable " and work with it. ==> works good.

It is just, that I think that Aspose.pdf does not support the " node-set() "
Is there a way in Aspose.pdf to calculate an overal sum. (i've looked at Formfields, but nothing seems to do the trick).

please help.
Thanks


Put the following lines in the xml file (heading) and call the xml file in your browser, you will see the result it should create.

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="XSLTFile.xsl"?>

In fact, the code in my upper post is used in Aspose.Pdf to process xslt and xml. I don’t know how to support msxsl:node-set when transform xml with xslt. Aspose.Pdf use the final xml to produce pdf file. I will study this issue. If you know the answer, please tell me.

Using "xsl.Transform" and the stylesheet with the "<Pdf xmlns="Aspose.Pdf">" element the result is NOT good
Commenting out the "<Pdf xmlns="Aspose.Pdf">" and running the transform results in an perfect outcome.
So, the problem lays in the tag. ==> any solutions?

<?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">
<xsl:template match="/">
==> RESULT of xsl Transform is OK
<xsl:for-each select="rapporten/rapport">
<xsl:variable name="tmpTotal">
<xsl:for-each select="vakken/vak">
<puntenDW>
<xsl:value-of select="puntenDW div 100 * tebehalenDW"/>
</puntenDW>
<tebehalenDW>
<xsl:value-of select="tebehalenDW"/>
</tebehalenDW>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="totpuntenDW">
<xsl:value-of select="sum(msxsl:node-set($tmpTotal)/puntenDW)"/>
</xsl:variable>
<xsl:variable name="tottebehalenDW">
<xsl:value-of select="sum(msxsl:node-set($tmpTotal)/tebehalenDW)"/>
</xsl:variable>
<Section>
<Text>
<Segment>
totaal:<xsl:value-of select="$totpuntenDW div $tottebehalenDW * 100"/>
</Segment>
</Text>
</Section>
</xsl:for-each>

The tag <Pdf xmlns="Aspose.Pdf"> has to be replaced by <Pdf>

Do you mean if I repleace <Pdf xmlns="Aspose.Pdf"> to then it works? But in my test it still won't work.