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
Atif SarfrazSubject: Creating Arrays using XSL
Author: Atif Sarfraz
Date: 28 Nov 2001 01:07 PM
Hi,

I was wondering whether there is a way to create arrays using XSL and then pass them to XSL Templates? Just like the arguments $arg1, can we create arrays and pass them to XSL templates for processing?

An example would be to create a list of values, and pass it to a function to display it within a table.

Regards,

Atif Sarfraz

Postnext
Minollo I.Subject: Re: Creating Arrays using XSL
Author: Minollo I.
Date: 28 Nov 2001 01:56 PM
You can assign nodesets to variables/parameters; that's probably close
enough to the concept of array.

You can do something like this:
{xsl:variable
name="myArray"}{item}item1{/item}{item}item2{/item}{/xsl:variable}

The XML document fragment assigned to the variable or parameter can be as
complicated as you want.

Then you can address individual items of the array doing something like:
{xsl:value-of select="$myArray/item[2]"/}

If you are not using the Stylus Studio processors, you will have to
explicitly convert $myArray into a nodeset before being able to run an
XPath query against it; for example, using MSXML you should change it to
select="msxml:node-set($myArray)/item[2]", where msxml is the MS extension
namespace xmlns:msxml="urn:schemas-microsoft-com:xslt" (Stylus Studio will
still understand and process it).

Hope this helps,
Minollo

Postnext
Atif SarfrazSubject: Re: Creating Arrays using XSL
Author: Atif Sarfraz
Date: 30 Nov 2001 12:17 PM
Hi,

Thanks for the information regarding creating Arrays. I am attaching a sample code at the end, which creates a drop down box and selects the option as specified in an argument. Its just an example if someone wants to use it.

The code works great in Excelon, but as you mentioned that I would have to use the Microsoft parser for running it in IE. I have a couple of questions in this regards.

1- Can you tell me whether Excelon and Microsoft are following the same standards, as set by w3 for XSL draft?
2- I don't want to run into vendor locking issue. Can you shed some light on that?
3- Would it be a better approach to use transformations at Server end instead of client end, so that they are supported in all browsers?
4- Can Excelon help me in a way to create server side java code for transformation?

Sorry for too many questions.

Regards,

Atif Sarfraz




{!-- select input Template is used to automatically make the default selection in the dropdown --}
{xsl:template name="selectTemplate"}
{xsl:param name='arg1' /}

{xsl:param name='arg2' }

{options}
{option value="Choose" selected=""}Choose Your State -->{/option}
{option value="AL"}Alabama{/option}
{option value="AK"}Alaska{/option}
{option value="AZ"}Arizona{/option}
{option value="AR"}Arkansas{/option}
{option value="CA"}California{/option}
{option value="CO"}Colorado{/option}
{option value="CT"}Connecticut{/option}
{option value="DE"}Delaware{/option}
{option value="DC"}District Of Columbia{/option}
{option value="FL"}Florida{/option}
{option value="GA"}Georgia{/option}
{option value="ID"}Idaho{/option}
{option value="IL"}Illinois{/option}
{option value="IN"}Indiana{/option}
{option value="IA"}Iowa{/option}
{option value="KS"}Kansas{/option}
{option value="KY"}Kentucky{/option}
{option value="ME"}Maine{/option}
{option value="MD"}Maryland{/option}
{option value="MI"}Michigan{/option}
{option value="MN"}Minnesota{/option}
{option value="MS"}Mississippi{/option}
{option value="MO"}Missouri{/option}
{option value="MT"}Montana{/option}
{option value="NE"}Nebraska{/option}
{option value="NV"}Nevada{/option}
{option value="NH"}New Hampshire{/option}
{option value="NY"}New York{/option}
{option value="NC"}North Carolina{/option}
{option value="ND"}North Dakota{/option}
{option value="OH"}Ohio{/option}
{option value="OK"}Oklahoma{/option}
{option value="OR"}Oregon{/option}
{option value="PA"}Pennsylvania{/option}
{option value="RI"}Rhode Island{/option}
{option value="SC"}South Carolina{/option}
{option value="SD"}South Dakota{/option}
{option value="TN"}Tennessee{/option}
{option value="TX"}Texas{/option}
{option value="UT"}Utah{/option}
{option value="VT"}Vermont{/option}
{option value="VA"}Virginia{/option}
{option value="WA"}Washington{/option}
{option value="WV"}West Virginia{/option}
{option value="WI"}Wisconsin{/option}
{option value="WY"}Wyoming{/option}
{/options}
{/xsl:param}

select="msxml:node-set($myArray)/item[2]"

{select name="select2" id="State"}
{xsl:for-each select="$arg2/options"}
{xsl:for-each select="option"}
{xsl:param name='arg3' }{xsl:value-of select="." /}{/xsl:param}
{xsl:param name='arg4' }{xsl:value-of select="./@value" /}{/xsl:param}

{b}{xsl:value-of select="$arg1" /}{/b}{br/}
{xsl:value-of select="$arg3" /}{br/}
{xsl:value-of select="$arg4" /}{br/}

{xsl:if test="$arg1=$arg4"}
{option selected=""}{xsl:value-of select="$arg3" /}{/option}
{xsl:attribute name="value"}{xsl:value-of select='$arg4' /}{/xsl:attribute}
{/xsl:if}
{xsl:if test="$arg1!=$arg4"}
{option}{xsl:value-of select="$arg3" /}{/option}
{/xsl:if}


{/xsl:for-each}
{/xsl:for-each}
{/select}
{/xsl:template}


{!-- To call the template use the code for a state --}

{xsl:call-template name='selectTemplate' }
{xsl:with-param name='arg1' }FL{/xsl:with-param}
{/xsl:call-template}

Postnext
Minollo I.Subject: Re: Creating Arrays using XSL
Author: Minollo I.
Date: 30 Nov 2001 12:26 PM

>...
>1- Can you tell me whether Excelon and Microsoft are following the same
>standards, as set by w3 for XSL draft?

The XSLT 1.0 specs don't allow for document fragments to be handled like
node-sets; all the processors I know of have implemented extensions to
handle this case (like the msxml:node-set() function).

XSLT 2.0 is removing the concept of document fragments, and will allow
operations like the one you can do in Stylus Studio without the need of any
function; rather than adding our own namespace extension, we have decided
to start supporting this model now.

Both MSXML and Stylus Studio support XSLT 1.0; Stylus Studio also supports
the MSXML extensions, like the above mentioned node-set() function and
script-based extension functions.

>2- I don't want to run into vendor locking issue. Can you shed some light
>on that?

See above.

>3- Would it be a better approach to use transformations at Server end
>instead of client end, so that they are supported in all browsers?

If you want to support non-IE browsers, yes.

>4- Can Excelon help me in a way to create server side java code for
>transformation?

The eXcelon XIS product is probably what you are looking for; XIS is an XML
repository, which embeds high performance XPath/XSLT processors.
You can read more about it and download a free evaluation version from:
http://www.exceloncorp.com/platform/index.shtml


Hope this helps,
Minollo

Posttop
Adam Van den HovenSubject: Re: Creating Arrays using XSL
Author: Adam Van den Hoven
Date: 02 Jan 2002 08:34 PM
Atif,

By now you've passed this by but someone else is going to ask the same question and I feel that an answer is still valid.

Two solutions have been proposed so far, the first is to select a vendor specific behavior (msxml:node-set() or the equivalent from saxon or what ever) or two wait for XSLT 2.0 to become an implemented recommendation.

However, there is an excellent XSL1.0 compliant solution to your problem that is better than both previous choices.

In your example you want to create a nodeset linking 2 character state names with the actual name of that state. The solution you provide is to hard code the nodeset in you template. But what happens when you want to run the template in both Canada and the US? Now you need to either extend your node set or have 3 different versions of the template (you are of course going to need to support the French province names... We are bilingual up here). As we all know from times past, hard coding is a big no-no.

A better solution is to do the following:


{xsl:stylesheet}
{xsl:param name="dataFileURI"/}
{xsl:variable name="stateProvNames" select="document($dataFileURI)" /}
{xsl:stylesheet}

Now you could hard code the dataFileURI (an OK stop gap measure) or you could retrieve the file from the parameters provided at run time, or do it at a template level. If I'm building a system that will be deployed at specific locations, I'm more likely to have one config file with a well defined name that contains everything else I would need to know (including the URI for my names files).

The advantage here is that you have now loaded the data as a nodeset in a way that EVERY XSLT1.0 processor must be able to handle. You can load the documents from any valid URI, although you should be careful when using the MSXML parser on a server if you are using HTTP requests(you need to set server safe HTTP flags and the like).

Hope it helps.

Adam

 
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.