views:

243

answers:

1

Hi All,

Can anybody who has worked on XSLT help me on this?

I am using XSL version 1.0.

I have declared a parameter in XSL file like:

<xsl:param name="HDISageHelpPath"/>

Now I am assigning the value to this parameter from an asp page . The value which I assign is "document('../ChannelData/Sage/help/ic/xml/HDI.xml')/HelpFiles/Help". Now I want to assign this parameter to the <xsl for each> like

<xsl:for-each select="msxsl:node-set($HDISageHelpPath)" >(This does not works)

But it does not works.I checked the parameter value by debugging it as below

<debug tree="$HDISageHelpPath">
    <xsl:copy-of select="$HDISageHelpPath"/>
</debug>

I am able to print the value and it seems correct. In fact when i assign the static path("document('../ChannelData/Sage/help/ic/xml/HDI.xml')/HelpFiles/Help") by hard-coding it , it works

<xsl:for-each select="document('../ChannelData/Sage/help/ic/xml/HDI.xml')/HelpFiles/Help"> (This works)

Can anyone please let me know why assigning the parameter to "for each" does not work?

Note: I have referred the site "http://www.dpawson.co.uk/xsl/sect2/N1553.html"

A: 

You can't easily evaluate dynamic strings as XPath expressions in XSLT 1.0. They must be hard-coded, normally.

There's EXSLT's dyn:evaluate(), but I doubt you can use that with the MXSML processor.

As an alternative approach, you could either try passing the file path only:

<xsl:param name="HDISageHelpFilePath"/>
<!-- ... -->
<xsl:for-each select="document($HDISageHelpFilePath)/HelpFiles/Help">
</xsl:for-each>

or making placeholder, replacing it with search-and-replace before you load the actual XSL code into the processor (as a string). This is a bit messy and error-prone, but it could give you the possibility to use an actual dynamic XPath expression.

<xsl:for-each select="%HELP_FILE_XPATH%">
</xsl:for-each>

Load the file as text, replace %HELP_FILE_XPATH% with your actual XPath, feed it to the processor. If it loads, you are fine, if it doesn't, your input XPath was malformed.

Tomalak
Hi Tomalak,First of all thanks for replying.Next I tried using your first option but unluckily it did not worked and gave the below error:Error Type:msxml3.dll (0x80004005)A reference to variable or parameter 'HDISageHelpFilePath' cannot be resolved. The variable or parameter may not be defined, or it may not be in scope.
Varun
Next regarding your second option, I would like to mention that I have just started working on xsl so am not sure what are you talking about. It would be better if we can talk on personal email id so that i can understand you better...I am online on [email protected] [email protected],Varun Doharey
Varun
I've changed the parameter name from `'HDISageHelpPath'` to `'HDISageHelpFilePath'` to emphasize that it's a file path, not an XPath - you might have missed that.
Tomalak
Also, I think we should discuss it here - in a private conversation nobody else would benefit. What I mean is this: You should open the XSL file as plain text first, do a search-and-replace on that text, and then load the modified text as the XSL document.
Tomalak
Well your idea of opening the file and then replacing seems okay for me.I will need to try this but in case if you find any other proper solution then please comment again. Thanks.
Varun