Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 4th, 2007, 01:51 PM
Authorized User
 
Join Date: Feb 2007
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Default Parse XML string parameter from XSLT

Hi,
         I am quite novice so XSLT. My scenario is as below.

i am passing xml string parameter to xslt from csharp.In xslt i am setting this xml string in variable( Which makes it RTF i guess).Now i am converting it to node-set using msxsl:node-set($myXMlStringVar).

Now how do i get inner element of my source xml ? here is snap of code

source xml (as parameter from csharp)

<RecommendedGreatest><FirstGreatest><X>LG:Assumpti on</X></FirstGreatest><SecondGreatest><Y>LG:Assumption</Y></SecondGreatest><ThirdGreatest><Z>LG:Assumption</Z></ThirdGreatest></RecommendedGreatest>


XSLT

---------
<xsl:variable name="RecommendedGreatest" select="jasper:GetCategoryOpportunity(3)" /> -->GetCategoryOpportunity is csharp function return xml string

<xsl:variable name="RecommendedNodeSet" select="msxsl:node-set($RecommendedGreatest)" />

How do i get "X" subelement value of "FirstGreatest" Element ?

Thanks
Maulik

 
Old December 4th, 2007, 01:59 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I don't think passing in a string with XML and calling msxsl:node-set on that string gives you a node-set of the nodes in the string.
If you want a node-set then have your function return an XPathNodeIterator, see the documentation at <URL:http://msdn2.microsoft.com/en-us/library/dfktf882(VS.80).aspx> which shows the XSLT/XPath <--> .NET mapping of types.

 
Old December 4th, 2007, 02:19 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to parse the string containing the XML and turn it into a tree of nodes. This is best done from your C# code, by invoking the XML parser. You should then pass the resulting XmlDocument node to the transformation. It's then already a nodeset (a set containing one node) so you don't need to invoke any extension functions.

Conversion of lexical XML to a tree (that is, parsing) never happens automatically, it only happens when you ask for it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 4th, 2007, 02:32 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Note that XPathDocument/XPathNavigator suffices for all XPath/XSLT operations, XmlDocument is an unnecessary overhead.

 
Old December 4th, 2007, 04:17 PM
Authorized User
 
Join Date: Feb 2007
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for quick reply. Now i am passing xpathdocument object to xslt ...how do i get inner node. do i need to create
script to navigate it ??

 
Old December 4th, 2007, 05:43 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Once the node is available within your stylesheet, say as the value of $param, you can navigate within the tree using XPath expressions, for example $param//a/b[xxx='25']

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 5th, 2007, 11:51 AM
Authorized User
 
Join Date: Feb 2007
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks so much Michael i got result the way i wanted.great help..Thanks to all of you...

regards







Similar Threads
Thread Thread Starter Forum Replies Last Post
How to parse a parameter out of a URL onClick() CodeBugger Javascript How-To 2 May 9th, 2008 02:27 PM
Parse String Issues jafuller Javascript How-To 3 January 18th, 2007 04:01 PM
Parse XML response atulb XML 1 October 30th, 2005 07:05 AM
about XML receive by tomcatand XML parse by java taianmhzy Servlets 0 May 20th, 2004 01:59 AM
about XML receive ang XML parse by tomcat taianmhzy Apache Tomcat 0 May 20th, 2004 01:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.