472,809 Members | 4,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,809 software developers and data experts.

XSLT with input parameter

Hello everyone,

is it possible to give a transformation a input parameter?
I want to use this parameter as a variable in my transformation.

thanks.

bye bembi
Jun 27 '08 #1
10 5678
bb*******@lycos.de wrote:
is it possible to give a transformation a input parameter?
I want to use this parameter as a variable in my transformation.
Yes, that is possible, you define a top-level xsl:param element with the
name of the parameter and then you use the API of your XSLT processor to
set that parameter before running the transformation.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:param name="p1"/>

<xsl:template match="/">
<xsl:value-of select="$p1"/>
</xsl:template>
</xsl:stylesheet>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
Thank you very much.

bembi
On 16 Mai, 17:04, Martin Honnen <mahotr...@yahoo.dewrote:
bbembi...@lycos.de wrote:
is it possible to give a transformation a input parameter?
I want to use this parameter as a variable in my transformation.

Yes, that is possible, you define a top-level xsl:param element with the
name of the parameter and then you use the API of your XSLT processor to
set that parameter before running the transformation.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:param name="p1"/>

<xsl:template match="/">
<xsl:value-of select="$p1"/>
</xsl:template>
</xsl:stylesheet>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #3
Hello again,

is it possible to give the XSLT a variable number of parameter and use
it in a array?
Thanks.
bye bembi

On 18 Mai, 18:28, "bbembi...@lycos.de" <bbembi...@lycos.dewrote:
Thank you very much.

bembi

On 16 Mai, 17:04, Martin Honnen <mahotr...@yahoo.dewrote:
bbembi...@lycos.de wrote:
is it possible to give a transformation a inputparameter?
I want to use thisparameteras a variable in my transformation.
Yes, that is possible, you define a top-level xsl:param element with the
name of theparameterand then you use the API of yourXSLTprocessor to
set thatparameterbefore running the transformation.
* *<xsl:stylesheet
* * *xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
* * *version="1.0">
* * *<xsl:param name="p1"/>
* * *<xsl:template match="/">
* * * *<xsl:value-of select="$p1"/>
* * *</xsl:template>
* *</xsl:stylesheet>
--
* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/- Zitierten Text ausblenden -

- Zitierten Text anzeigen -
Jun 27 '08 #4
bb*******@lycos.de wrote:
is it possible to give the XSLT a variable number of parameter and use
it in a array?
For the first: Parameters can have default values. Or you could pass a
parameter which your stylesheet then parses data out of.

XSLT has no concept of "arrays". Some processors will let you pass in
non-XSLT objects but the only thing you can do with them, really, is to
pass them along to extension functions.

You might get more useful answers if you told us what you're trying to
do rather than asking whether a particular approach is possible.
Jun 27 '08 #5
bb*******@lycos.de wrote:
is it possible to give the XSLT a variable number of parameter and use
it in a array?
Depending on the XSLT processor you use it might be possible to pass in
an XML document exposed as a node-set to XSLT/XPath. For instance MSXML
allows you to build and pass in an XML DOM document.
XslCompiledTransform allows that too. See
http://msdn.microsoft.com/en-us/libr....addparam.aspx
for the .NET types you can pass in and how the translate into XPath/XSLT
types.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #6
Thanks for the answers so far.

To give you the whole story:
I want to do this: I have a XML like:
<root>
<entry type='a' />
<entry type='b' />
<entry type='c' />
</root>

Now I want to pass a variable number of types. All these will be
exported:
Example:
parameters: a, b
Output:
<root>
<entry type='a' />
<entry type='b' />
</root>

bye bembi

On 21 Mai, 15:47, "Joseph J. Kesselman" <keshlam-nos...@comcast.net>
wrote:
bbembi...@lycos.de wrote:
is it possible to give theXSLTa variable number ofparameterand use
it in a array?

For the first: Parameters can have default values. Or you could pass aparameterwhich your stylesheet then parses data out of.

XSLThas no concept of "arrays". Some processors will let you pass in
non-XSLTobjects but the only thing you can do with them, really, is to
pass them along to extension functions.

You might get more useful answers if you told us what you're trying to
do rather than asking whether a particular approach is possible.
Jun 27 '08 #7
bb*******@lycos.de wrote:
parameters: a, b
Output:
<root>
<entry type='a' />
<entry type='b' />
</root>
I'd suggest passing a single parameter which contains a delimited string
of the values you want to match, and writing the test to use it in that
form... exactly as you've shown it here.

I did a simple and sloppy version of that in part 2 of my "styling
stylesheets" article on DeveloperWorks (http://www.ibm.com/xml).
Jun 27 '08 #8
bb*******@lycos.de wrote:
To give you the whole story:
I want to do this: I have a XML like:
<root>
<entry type='a' />
<entry type='b' />
<entry type='c' />
</root>

Now I want to pass a variable number of types. All these will be
exported:
Example:
parameters: a, b
Output:
<root>
<entry type='a' />
<entry type='b' />
</root>
Which XSLT processor do you use?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #9
I am not sure which XSLT processor will be used.
The transformation will be integreated in a existing system. I think
it is saxon 8.?

bye bembi
On 21 Mai, 18:25, Martin Honnen <mahotr...@yahoo.dewrote:
bbembi...@lycos.de wrote:
To give you the whole story:
I want to do this: I have a XML like:
<root>
* <entry type='a' />
* <entry type='b' />
* <entry type='c' />
</root>
Now I want to pass a variable number of types. All these will be
exported:
Example:
parameters: a, b
Output:
<root>
* <entry type='a' />
* <entry type='b' />
</root>

WhichXSLTprocessor do you use?

--

* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/- Zitierten Text ausblenden -

- Zitierten Text anzeigen -
Jun 27 '08 #10
bb*******@lycos.de wrote:
I am not sure which XSLT processor will be used.
The transformation will be integreated in a existing system. I think
it is saxon 8.?
Well there are different versions of Saxon 8 supporting different
version of the XSLT 2.0 draft but with Saxon 8.9 or 9.0 which support
the final XSLT 2.0 specification you could easily use the tokenize
function to split up a string value passed in into a sequence of strings:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">

<xsl:output method="xml" indent="yes"/>

<xsl:param name="types" as="xs:string"/>

<xsl:variable name="type-list" as="xs:string*"
select="tokenize($types, ',')"/>

<xsl:template match="root">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="entry[@type = $type-list]"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

Then you could use Saxon 9 from the command line as follows:

java -jar saxon9.jar -s:input.xml -xsl:stylesheet.xsl types=a,b
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Federico | last post by:
Hi all, I don't know if this topic is perhaps a little bit off-topic, anyway I have a strange problem in transforming an XML file in an HTML file using XSLT form a Java program written with...
8
by: Maciej Wegorkiewicz | last post by:
Hi, I have small experience in XSLT processing and I have a problem which I cannot solve. Can you look at it? I have an input file containing info about bank accounts like this: (...) <acc...
0
by: resolutionsnet | last post by:
Hi, I raised as message earlier in this forum with regards to an error when preforming a XSLT transform (see bottom of this message). On further investigation I'm find that some of the XSLT...
4
by: gualtmacchi | last post by:
I'm processing an XML input file getting a plain text file where from M nodes I got N output lines... It's not relevant but the input file is a recordset coming from a database and the output is...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
4
by: shaun roe | last post by:
I should like to count the frequency of strings embedded in a longer string, space separated. Specifically, I have: <phiModule> 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 8 5 5 5 6 6 6 7 7 7 7 7 7 7 7...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
2
by: Jonny B | last post by:
Hi all, I'm working on an a clientside xslt using jscript that passes a parameter to the xsl. I've got it working no problem in IE but cant get it to work in Mozilla. Can anyone help? This is...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.