Problem using msxsl:node-set with xsl:param

ipg

Usenet Archive
Joined
Aug 19, 2003
Messages
1
Reaction score
0
I am running into issues passing a parameter (that is a XML string) into a stylesheet and using msxsl:node-set to parse the string. Can someone please explain why.

my html:
var xsl = new ActiveXObject("MSXML2.FreeThreadedDomDocument.3.0"); xsl.async = false; xsl.load("campaignHtml.xsl"); var template = new ActiveXObject("MSXML2.XSLTemplate"); template.stylesheet = xsl; processor = template.createProcessor; processor.input = xmlDocument; processor.addParameter( "conferenceDocument" ,xmlConferenceDocument.documentElement.xml); processor.transform;

my xsl:

<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.1"> <xsl:eek:utput method="html" indent="yes"/>

<xsl:param name="conferenceDocument" select="."/>

<!-- the function does not return anything when a parameter is used
-->
<xsl:value-of select=
"msxsl:node-set($conferenceDocument)/ROWSET/ROW/CONFERENCE_CODE" />

....

<!-- However when I print the parameter to screen and hardcode the screen output into a variable tag, the function works fine. -->

<xsl:variable name="conferenceDocument">
<ROWSET><ROW><CONFERENCE_ID>1</CONFERENCE_ID><CONFERENCE_CODE>SEC</CONFERENCE_CODE><CONFERENCE_NAME>Southeastern Conference</CONFERENCE_NAME></ROW><ROW><CONFERENCE_ID>622</CONFERENCE_ID><CONFERENCE_CODE>NONE</CONFERENCE_CODE><CONFERENCE_NAME>Unassigned</CONFERENCE_NAME></ROW><ROW><CONFERENCE_ID>111</CONFERENCE_ID><CONFERENCE_CODE>ACC</CONFERENCE_CODE><CONFERENCE_NAME>Atlantic Collegiate Conference</CONFERENCE_NAME></ROW><ROW><CONFERENCE_ID>324</CONFERENCE_ID><CONFERENCE_CODE>B12</CONFERENCE_CODE><CONFERENCE_NAME>Big XII</CONFERENCE_NAME></ROW></ROWSET> </xsl:variable>

<xsl:value-of select=
"msxsl:node-set($conferenceDocument)/ROWSET/ROW/CONFERENCE_CODE" />

Can someone please explain why. Why is the parameter not being evaluated like the text written between the var tags above. Please enlighten me. I have spent 2 days on this.

Thanks,
Patrick
 

Oleg Tkachenko

Usenet Archive
Joined
Nov 19, 2002
Messages
71
Reaction score
0
ipg wrote:

I am running into issues passing a parameter (that is a XML string) into a stylesheet and using msxsl:node-set to parse the string.

Why do you think msxsl:node-set function parses a string????
 

Patrick Gresham

Usenet Archive
Joined
Aug 19, 2003
Messages
4
Reaction score
0
msxsl:node-set should process the string as it's value looks exactly like a node tree fragment. The nodes are well-balanced. As mentioned before, I can make the function work by setting the output of the parameter between xsl:variable tags by writing it out in the xsl. I cannot understand why the parameter is not evaluated the same as hard coding the value.

*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
 

Oleg Tkachenko

Usenet Archive
Joined
Nov 19, 2002
Messages
71
Reaction score
0
ipg said:
processor.addParameter(
"conferenceDocument"
,xmlConferenceDocument.documentElement.xml);
Why don't you pass xmlConferenceDocument.documentElement as is? Isn't it weird to serialize document to string just to pass it to XSLT and then parse it back again?
 

Dimitre Novatchev

Usenet Archive
Joined
Nov 7, 2000
Messages
737
Reaction score
0
Two things:

1. The xxx:node-set extension function does not parse a string. A string is not an RTF (Result Tree Fragment). An RTF is a tree of nodes.

2. You should pass as parameter the node-set itself, which you have already parsed (xmlConferenceDocument.documentElement) and not its string representation. Then you do not need xxx:node-set at all, the parameter is a node-set -- not an RTF.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"ipg" wrote:

I am running into issues passing a parameter (that is a XML string) into a stylesheet and using msxsl:node-set to parse the string. Can someone please explain why.

my html:
var xsl = new ActiveXObject("MSXML2.FreeThreadedDomDocument.3.0"); xsl.async = false; xsl.load("campaignHtml.xsl"); var template = new ActiveXObject("MSXML2.XSLTemplate"); template.stylesheet = xsl; processor = template.createProcessor; processor.input = xmlDocument; ...
<ROWSET><ROW><CONFERENCE_ID>1</CONFERENCE_ID><CONFERENCE_CODE>SEC</CONFERENC E_CODE><CONFERENCE_NAME>Southeastern Conference</CONFERENCE_NAME></ROW><ROW><CONFERENCE_ID>622</CONFERENCE_ID><CO NFERENCE_CODE>NONE</CONFERENCE_CODE><CONFERENCE_NAME>Unassigned</CONFERENCE_ NAME></ROW><ROW><CONFERENCE_ID>111</CONFERENCE_ID><CONFERENCE_CODE>ACC</CONF ERENCE_CODE><CONFERENCE_NAME>Atlantic
Collegiate
Conference</CONFERENCE_NAME></ROW><ROW><CONFERENCE_ID>324</CONFERENCE_ID><CO NFERENCE_CODE>B12</CONFERENCE_CODE><CONFERENCE_NAME>Big
XII</CONFERENCE_NAME></ROW></ROWSET>
</xsl:variable>

<xsl:value-of select=
"msxsl:node-set($conferenceDocument)/ROWSET/ROW/CONFERENCE_CODE" />

Can someone please explain why. Why is the parameter not being evaluated like the text written between the var tags above. Please enlighten me. I have spent 2 days on this.

...
 

Patrick Gresham

Usenet Archive
Joined
Aug 19, 2003
Messages
4
Reaction score
0
You get credit for the assist. Your response was not exactly correct, but good enough. The solution is one of those things that make me say wow!

First, you were on the right track with "why convert the node set to a string when it is already an xml doc." So I made this adjustment in the javascript

i.e.:
processor.addParameter("xmlDoc", xmlId)
not
processor.addParameter("xmlDoc", xmlId.documentElement)

Next, once the parameter is passed to the XSL, it is a tree fragment, set of nodes. You have to call xxx:node-set so that XSL will treat it is such.

i.e.
<xsl:param name="xmlDoc" select="." />
<xsl:value-of select="msxsl:node-set($xmlDoc/Element)" />

This is so cool because you can pass multiple XML documents to the XSL stylesheet dynamically. This will come into use when you are building a select list of options with an external document and the source document stores the option selected.

I am posting this because I am sure some poor soul will spend 3 days on this as I have. By the way, you have to include a urn with the node-set function available. You can get that from msxsl, xalan, and others.

*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
 

Patrick Gresham

Usenet Archive
Joined
Aug 19, 2003
Messages
4
Reaction score
0
Opps made a typo in the example above:
<xsl:value-of select="msxsl:node-set($xmlDoc)/Element" />

*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
 

Dimitre Novatchev

Usenet Archive
Joined
Nov 7, 2000
Messages
737
Reaction score
0
"Patrick Gresham" wrote:

You get credit for the assist. Your response was not exactly correct, but good enough. The solution is one of those things that make me say wow!

First, you were on the right track with "why convert the node set to a string when it is already an xml doc." So I made this adjustment in the javascript

i.e.:
processor.addParameter("xmlDoc", xmlId)
not
processor.addParameter("xmlDoc", xmlId.documentElement)
...

No. It is just a regular node-set. Remove the call to the msxsl:node-set ext. function and see that you'll get no error.

The definition of an RTF requires that its contents is produced by the transformation itself. Also, an RTF is defined *only* as the contents of an xsl:variable. Both of these two conditions are not satisfied in your example.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 

Mark Johnson

Usenet Archive
Joined
Nov 27, 2000
Messages
58
Reaction score
0
Dimitre Novatchev said:
Two things:

1. The xxx:node-set extension function does not parse a string. A string is not an RTF (Result Tree Fragment). An RTF is a tree of nodes.

2. You should pass as parameter the node-set itself, which you have already parsed (xmlConferenceDocument.documentElement) and not its string representation. Then you do not need xxx:node-set at all, the parameter is a node-set -- not an RTF.

What's the difference between a "tree of nodes", then, and a "node-set"?
 

Mark Johnson

Usenet Archive
Joined
Nov 27, 2000
Messages
58
Reaction score
0
Oleg Tkachenko said:
Mark Johnson wrote:
The difference between result-tree fragment and nodeset:
http://www.w3.org/TR/xslt.html#section-Result-Tree-Fragments

Doesn't really say what it is, though. It mentions vague - extension functions - from a small section further on. But I assume a result fragment is a node-set representation of part of the result of the xslt transform. And a node-set, generally, is the subset of the XML as returned by an XPath expr.

It's only XSLT 1.0 related data type, XSLT 1.1 and 2.0 managed to get rid of it.

So there's only - node-set. I've seen various articles of yours, say at MSDN. You've been referring to a proposed 2.0. Is it available? Is it part of an msxml 4? 5?
 

Oleg Tkachenko

Usenet Archive
Joined
Nov 19, 2002
Messages
71
Reaction score
0
Mark said:
Doesn't really say what it is, though. It mentions vague - extension functions - from a small section further on. But I assume a result fragment is a node-set representation of part of the result of the xslt transform. And a node-set, generally, is the subset of the XML as returned by an XPath expr.
Well, that's not quite clean explanation too. RTF is actually just a temporary tree. The only way to produce it is using a variable. Variable is bound to RTF if it has any content (hence doesn't have select attribute). The same goes for xsl:param and xsl:with-param actually:
<xsl:variable name="rtf">
<a>foo</a>
</xsl:variable>
It's called result-tree fragment, becuase all you can do with it is to copy it out (usually to the result tree) either by xsl:value-of or xsl:copy-of.
So there's only - node-set. I've seen various articles of yours, say at MSDN. You've been referring to a proposed 2.0. Is it available? Is it part of an msxml 4? 5?
It's still working draft and there is no MS implementation yet. I'm aware of the only experimental XSLT2.0 impl - Saxon 7.X.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,224
Members
248,132
Latest member
henrywalsh

Latest Threads

Top