473,769 Members | 6,286 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing Parameter to Transform of XML to XML

The following transformation puzzles me when trying to transform XML to XML.

I get an exception "THE EXPRESSION PASSED TO THIS METHOD SHOULD RESULT IN A
NODESET" at the last line "xmlDoc.Load(xr )" when I run the code.

I previously tried it all without a parameter and hard-coded the value into
the 'apply-templates' statement and the tranform produced

the result that I expected but when I inset the parameter I get the
exception.

I would appreciate it if someone could look over the code and identify which
part of the code causes the fault

I use VB.NET 2003 and .NET 1.1

cheers,
Craig
------------------ regs.xml ------------
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="regs.xslt "?>
<AllCtls>
<Ctl>
<cl>2</cl>
<ol>AAAAAAAAA </ol>
</Ctl>
<Ctl>
<cl>6</cl>
<ol>BBBBBBBBB </ol>
</Ctl>
<Ctl>
<cl>3</cl>
<ol>CCCCCCCCC </ol>
</Ctl>
<Ctl>
<cl>6</cl>
<ol>DDDDDDDDD </ol>
</Ctl>
</AllCtls>
------------ regs.xslt -------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:param name='myFilter' />

<xsl:template match="/">
<AllCtls>
<xsl:apply-templates select='$myFilt er' />
</AllCtls>
</xsl:template>

<xsl:template match="Ctl">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>


----------- VB.Net code ----------------
Dim xmlDoc As New XmlDocument
xmlDoc.Load("re gs.xml")

Dim xslt As XslTransform = New XslTransform
xslt.Load("regs .xslt")

Dim xslArg As XsltArgumentLis t = New XsltArgumentLis t

Dim str As String = "/AllCtls/Ctl[cl='6']"
xslArg.AddParam ("myFilter", "", str)

Dim res As XmlResolver
Dim nav As XPathNavigator = xmlDoc.CreateNa vigator()

Dim xr As XmlReader = xslt.Transform( nav, xslArg, res)

Dim xmlDoc As New XmlDocument
xmlDoc.Load(xr)
------------------------------------------------------------
Nov 12 '05 #1
2 4033
Craig Petrie wrote:
Dim xmlDoc As New XmlDocument
xmlDoc.Load("re gs.xml")

Dim xslt As XslTransform = New XslTransform
xslt.Load("regs .xslt")

Dim xslArg As XsltArgumentLis t = New XsltArgumentLis t

Dim str As String = "/AllCtls/Ctl[cl='6']"
xslArg.AddParam ("myFilter", "", str)


Hehe, nice one. Can you pass fragment of C# source code to a method
call? I don't think so.
What you are passing here is plain string. There is no such thing as
"string-which-is-actually-XPath-expression" type in XSLT.
Instead select nodes you want to pass and just pass them. Something like

XPathNavigator nav = xmlDoc.CreateNa vigator();
xslArg.AddParam ("myFilter", "", nav.Select("/AllCtls/Ctl[cl='6']"));

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2
Many thanks Oleg - much appreciated

I am new to xsl and its good to get advice from experts such as yourself.

I tried your solution and it worked very well - many thanks.

cheers,
Craig
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:OV******** ********@TK2MSF TNGP09.phx.gbl. ..
Craig Petrie wrote:
Dim xmlDoc As New XmlDocument
xmlDoc.Load("re gs.xml")

Dim xslt As XslTransform = New XslTransform
xslt.Load("regs .xslt")

Dim xslArg As XsltArgumentLis t = New XsltArgumentLis t

Dim str As String = "/AllCtls/Ctl[cl='6']"
xslArg.AddParam ("myFilter", "", str)


Hehe, nice one. Can you pass fragment of C# source code to a method
call? I don't think so.
What you are passing here is plain string. There is no such thing as
"string-which-is-actually-XPath-expression" type in XSLT.
Instead select nodes you want to pass and just pass them. Something like

XPathNavigator nav = xmlDoc.CreateNa vigator();
xslArg.AddParam ("myFilter", "", nav.Select("/AllCtls/Ctl[cl='6']"));

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2596
by: Mitch Cunningham | last post by:
HI, i am trying to use the following code to do an xslt transform using php 4/sablotron with additional optional arguments. can anybody tell me what i am doing wrong ? i was expecting the output "one two" from the sample.xsl transform but it seems to treat the variable as a literal (see below)... trans.php --------
1
2717
by: Daryl | last post by:
Hello I am using apply-templates and would like to pass a parameter to the template using with-param. Using call-template passes the parameter, but when I use apply-templates, the parameter seems to be lost. Can parameters be passed with apply-templates? Any ideas? <!--xml--> <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="tran2.xsl"?> <doc>
1
1419
by: Steven T. Hatton | last post by:
If I do: typedef vector<size_t> v_T; pair<v_T, v_T> b_T; b_T bounds(v_T(n), v_T(n)); // if that doesn't work // std::make_pair(v_T(n), v_T(n)); b_T diff_v(n); void populate_bounds(&bounds); // all bounds.first <= bounds.second
1
2045
by: Gary Whittle | last post by:
Hello, Can someone explain the easiest way to pass an external value to an XSL file? If I have a variable within my ASP file called "ClickArea", can I send the value to my XSL file? I believe I need to use Addparameter somehow, but I have no joy. If someone could post a super quick very basic example of how Addparameter
2
2841
by: Oleksandr Brovko | last post by:
Code sample below demonstrates following: We have sample extension object with 2 methods TestMethod - takes XPathNodeIterator as a parameter TestMethod2 - takes string as a parameter also we have CustomXmlResolver, stylesheet takes <XML>SourceDoc</XML> as source XML document also sylesheet retreives <XML>CustomXmlResolverData</XML> XML document through the document function and CustomXmlResolver now we pass $externalDoc/XML node set to...
7
2868
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
3
1734
by: sp | last post by:
the xml file i used <catalog> <cd> <title year="1990">Empire Burlesque</title> <artist>Bob Dylan</artist> <price>10.90</price> </cd> <cd>
6
2523
by: David Schwartz | last post by:
I have a template that searches for and replaces found instances of strings in other strings and replaces them with yet another string. These strings are passed to the template as parameters, not surprisingly. It so happens at the moment that I need to replace instances of spaces with a plus sign. Unfortunately, I don't know how to pass a space effectively, the template just doesn't get it. Any thoughts re how to fix this would be...
0
977
by: bluefootedpig | last post by:
hello, I'm wondering about passing in an xml file to an xslt document, i need need to querry the document for values. File1.xml <root> <address> ...data.... </address> </root>
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.