|
-
Sep 11th, 2003, 08:00 AM
#1
Thread Starter
Fanatic Member
What is .NET equiv of MSXML4 transformNode
Hi,
I have an xml file and an xslt file. I want to be able to select the xml node in VB.NET and transform only that node while still having a reference to the rest of the document from within the xslt. This is so that I can use any references to other parts of the document. In VB6, this was easy, you simply select the node of choice and use the transformNode function. In .NET however, I cannot find an equivalent function. I have tried creating an XPathNavigator from the node and passing that into the transformation, but it still processes the entire document. What can I do to get the xslt processor to process only the selected node?
XML
---
<doc>
<paragraph id="1">
<line>Here is line 1,1</line>
<line>Here is line 1,2</line>
<line>Here is line 1,3</line>
<line>Here is line 1,4</line>
</paragraph>
<paragraph id="2">
<line>Here is line 2,1</line>
<line>Here is line 2,2</line>
<line>Here is line 2,3</line>
<line>Here is line 2,4</line>
</paragraph>
<paragraph id="3">
<line>Here is line 3,1</line>
<line>Here is line 3,2</line>
<line>Here is line 3,3</line>
<line>Here is line 3,4</line>
</paragraph>
</doc>
XSLT
----
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl utput method="text" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="paragraph">
<xsl:for-each select="line">
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
VB6 output [when paragraph id=1 is selected] <- desired output
----------
Here is line 1,1
Here is line 1,2
Here is line 1,3
Here is line 1,4
VB.NET output [when paragraph id=1 is selected]
-------------
Here is line 1,1
Here is line 1,2
Here is line 1,3
Here is line 1,4
Here is line 2,1
Here is line 2,2
Here is line 2,3
Here is line 2,4
Here is line 3,1
Here is line 3,2
Here is line 3,3
Here is line 3,4
Thanks
-
Sep 11th, 2003, 08:18 AM
#2
PowerPoster
You need to use the XslTransform class from the System.Xml.Xsl namespace.
Code:
using System;
using System.IO;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Xml;
public class TransformExample {
static void Main() {
XslTransform xsl = new XslTransform();
xsl.Load("SignatureCapture.xslt");
XPathDocument doc = new XPathDocument("srs.xml");
XmlWriter writer = new XmlTextWriter(Console.Out);
xsl.Transform(doc, null, writer, null);
}
}
Last edited by Lethal; Sep 11th, 2003 at 08:45 AM.
-
Sep 15th, 2003, 08:13 AM
#3
Thread Starter
Fanatic Member
I have used the XslTransform, but this processes the entire xml document regardless of the position of the XPathNavigator. I am looking for a way of only parsing the current node of the XPathNavigator.
In the MSXML4 objects, we can use the TransformNode function of the IXMLNode interface to achieve this, however, there does not appear to be an equivalent function in the .NET architecture.
I have read through M$'s documentation, and they recommend extracting the xml string from the node and creating a separate xml document object with this string, but this is no good to me since I need to evaluate references to the rest of the document from within this node.
I can't believe that M$ would have dropped functionality from its when creating the .NET architecture.... ??? There must be a way to do this somehow.....!!!!
If you look at the xml and output in my previous post, you will see the difference in the results from the two technologies.
Basically, the .NET architecture does not hand the current position to the xslt. The xslt always starts from the top, so, if you want to evaluate a particular node, you have to build up some xpath and pass it to the xslt as an input parameter....
So great...!!! Thats easy enough! Only thing is there's no way of getting the xpath from a node object! So you have to map the xpath manually..... Try it out. She's not pretty! But if its the only way, SO BE IT!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|