XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Peter RissenbergSubject: xsl:variable holding the name of an xsl:param
Author: Peter Rissenberg
Date: 05 Dec 2006 06:20 AM
Hello all,

(Not sure if this should be posted in the XSL or XQuery list...)

I have the following situation:

I am developing a set of XSLs that take an XML doc as input and generate an HTML+Javascript editor for this particular XML doc.
These XSLs are invoked by a native Windows app, using the IE ActiveX control in hosted mode (so, only the latest version of MSXML is available!); something like the AJAX concept, but all on the desktop.

The only straight-forward way that the native app has to pass context information to the XSLs is via runtime xsl:params.

Among others, the native app passes the following xsl:params
- idList: a comma-separated list of object ids that need special processing
- <id1>, <id2>...: A number of xsl:params, each named after each value in the list and containing some information.

Question:
Is there a way to use the value of an xsl:variable as a QName to get the value of one xsl:param?

For example, in the following fragment what should be added (if anything) in the placeholder to get the value of runtime xsl:param named $objectId?

<xsl:template name="processInfo">
<xsl:param name="objectId"/>

<xsl:variable name="isDirty" select="contains($idList, $objectId)"/>

<xsl:if test="$isDirty = 'true'">
<xsl:variable name="objectValue" select="[-->Missing part<--]"/>
<!-- Some other, nasty stuff happenning here -->
</xsl:if>
</xsl:template>

I have been googling all day about this but nothing has come up!
Could it be that I am asking the impossible?

Thank you for any help or hint that you may provide.

Cheers,
S.

Postnext
Ivan PedruzziSubject: xsl:variable holding the name of an xsl:param
Author: Ivan Pedruzzi
Date: 05 Dec 2006 08:30 AM
Hi Peter,

XSLT dosn't allow to build an expression where the parameter name is computed.

I suggest to try a different approach: rather then passing a parameter for each "object" you should use a single parameter that holds a XML fragment.

<objects>
<id1></id1>
<id2></id2>
...
</objects>

Then you will be able to use XPath to select a node in the fragment.

$param//*[local-name() = $objectid]

Hope this helps
Ivan Pedruzzi
Stylus Studio Team
http://www.stylusstudio.com/xml_download.html

Postnext
Peter RissenbergSubject: xsl:variable holding the name of an xsl:param
Author: Peter Rissenberg
Date: 06 Dec 2006 04:32 AM
Hello, Ivan,

Thank you very much for your suggestion; I find it really clever.

However, there is a little problem:

I modified the xsl:param declaration as follows

<xsl:param name="dirtyTransTemplates">
<data>
<template id="id1">
<!-- Some HTML code here -->
</template>
<template id="id2">
<!-- Some more HTML code -->
</template>
...
</data>
</xsl:param>

and the fragment inside my code as follows (I want the complete contained HTML)
<xsl:variable name="oldTransLangText">
<xsl:copy-of select="$dirtyTransTemplates//data/template[@id = $id]"/>
</xsl:variable>

When I try to process the underlying XML, I get an error from the MSXML parser that
"Reference to variable or parameter dirtyTransTemplates must evaluate to a node list"

However, if I modify my selector to something like
<xsl:variable name="oldTransLangText">
<xsl:copy-of select="$dirtyTransTemplates"/>
</xsl:variable>
there is no runtime error and I get back all of the contained nodes, but of course this is not what I want.

Hmm, what am I doing wrong?
Is there something more needed?

Cheers

Posttop
Peter RissenbergSubject: xsl:variable holding the name of an xsl:param
Author: Peter Rissenberg
Date: 06 Dec 2006 04:59 AM
Hello, again,

I was really quick to post another question, when I should first check around a bit.

So, I will answer my own question, hoping this will help someone else in the future.

The missing piece of the puzzle is the need to use an extension function to transform the retrieved XML fragment from the global xsl:param into a processable node-list

So, for MSXML to work what was needed additionally was
1) the declaration of the appropriate namespace at the top of the XSL
...xmlns:msxsl="urn:schemas-microsoft-com:xslt"...>

2) the use of function node-set in the selection expression
<xsl:variable name="oldTransLangText">
<xsl:copy-of select="msxsl:node-set($dirtyTransTemplates)//data/template[@id = $id]"/>
</xsl:variable>

3) The escaping of all content to be processed. This is needed in my case, where I retrieve the fragment using xsl:value-of and use an HTML attribute to store it). So, instead of
<p>Product <strong>some product</strong></p>
I needed to have the following in order to get a proper HTML fragment
%u003Cp%u003EProduct %u003Cstrong%u003Esome product%u003C/strong%u003E%u003C/p%u003E

Thank you VERY VERY MUCH for your help and idea!!!

Cheers

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.